visualforce page shows uknown method error - salesforce

I have 2 wrapper class as below
public class Wr_Studennt{
public string name{get;set;}
public decimal salary{get;set;}
public decimal exp{get;set;}
public string technology{get;set;}
}
public class Wr_Address {
public String city{get;set;}
public string place{get;set;}
public string pincode{get;set;}
public String state{get;set;}
}
I have apex class as below
public class wr_Student_Address {
public Wr_Studennt st{set;get;}
public wr_student_Address()
{
st=new Wr_Studennt();
}
public void setstudent(string name,decimal salary,decimal exp,string technology)
{
st.name=name;
st.salary=salary;
st.exp=exp;
st.technology=technology;
}
}
My VF page isas below
<apex:page controller="wr_Student_Address">
<apex:form>
<apex:pageblock title="Student Details">
<apex:pageBlockSection>
<apex:outputLabel value="Name: "/>
<apex:inputText value="{!name}" />
<apex:outputLabel value="Salary: "/>
<apex:inputText value="{!salary}" />
<apex:outputLabel value="Exp: "/>
<apex:inputText value="{!exp}" />
<apex:outputLabel value="Technology: "/>
<apex:inputText value="{!technology}" />
<apex:commandButton value="setstudent" action="{! setstudent}" />
</apex:pageBlockSection>
</apex:pageblock>
</apex:form>
</apex:page>
It shows
Unknown property 'wr_Student_Address.name' error in line 0.
Please help me solving this issue.
visualforce page shows
unknown method error

Your page controller wr_Student_Address has only 1 property: st. There's no field called name directly in this class.
Try with merge field {!st.name}

Related

Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: [] Error is in expression '{!edit}' [[[[[[

when i update my existing data with visualforce page , i got thi error
Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: []
Error is in expression '{!edit}' in page contract_object: Class.ContractController.edit: line 28, column 1
An unexpected error has occurred. Your development organization has been notified.
please complite my code without error
My Visual force Code is
<apex:page Controller="ContractController" sidebar="false" showHeader="false">
<apex:form >
<apex:pageBlock title="Contract Form">
<apex:pageBlockSection >
<apex:selectList size="1">
<apex:selectOptions value="{!contactlist}">
</apex:selectOptions>
</apex:selectList>
</apex:pageBlockSection>
<apex:pageBlockSection columns="1">
<apex:inputField value="{!conObj.Name}" />
<apex:inputField value="{!conObj.First_Name__c}" />
<apex:inputField value="{!conObj.Last_Name__c}" />
<apex:inputField value="{!conObj.Phone_Number__c}" />
<apex:inputField value="{!conObj.Address__c}" />
<apex:inputField value="{!conObj.Email__c}" />
</apex:pageBlockSection>
<apex:pageBlockButtons location="bottom">
<apex:commandButton value="Save" action="{!save}"/>
<apex:commandLink value="Edit" action="{!edit}"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
my controller code
public class ContractController {
public List<Contract__c> ContractTemp = new List<Contract__c>();
public List<SelectOption> contactlist
{
get
{
ContractTemp = [Select Id,Name from contract__c];
contactlist = new List<SelectOption>();
for(Contract__c con : ContractTemp)
{
contactlist.add(new SelectOption(con.Id, con.Name));
}
return contactlist;
}
set;
}
public ContractController() {
conObj = new Contract__c();
}
public Contract__c conObj {get; set;}
public void save() {
insert conObj;
}
public void edit() {
update conObj;
}
}

While creating a form using salesforce visual force pages and saving the data, it results in an error

While creating a form using salesforce visual force pages and saving the data, it results in the following error:
Attempt to de-reference a null object
Error is in expression '{!save}' in component apex:commandButton in page contract_object: Class.ContractController.save: line 7, column 1
An unexpected error has occurred. Your development organization has been notified.
My apex code is as follows:
<apex:page Controller="ContractController" sidebar="false" showHeader="false">
<apex:form >
<apex:pageBlock title="Contract Form">
<apex:pageBlockSection columns="1">
<apex:inputField value="{!conObj.Name}"/>
<apex:inputField value="{!conObj.First_Name__c}" />
<apex:inputField value="{!conObj.Last_Name__c}" />
<apex:inputField value="{!conObj.Phone_Number__c}" />
<apex:inputField value="{!conObj.Address__c}" />
<apex:inputField value="{!conObj.Email__c}" />
<apex:commandButton value="Save" action="{!save}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
The controller is as follows:
public with sharing class ContractController {
public Contract__c conObj {get; set;}
public void newContract() {
conObj = new Contract__c();
}
public void save() {
insert conObj;
}
}
Your newContract() is not called anywhere.
You can make it run as constructor (special function with name same as class name)
public ContractController () {
conObj = new Contract__c();
}
If you haven't used constructors before you'll have hard time.
Or a slightly "pro" way would be to read up about "Standard Controller" and extension classes (that's a change mostly in apex side of stuff but also in 1st line of your VF)

how to insert the masterdetails field in controller salesforce?

Here in stud Sobject there are two master_deatils i.e course and trainer name. I need to insert the data. But not able to insert.Please help me...Thaks In Advance..
<apex:page controller="insert_cc_Class">
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton value="SAVE" action="{!save}"/>
<apex:commandButton value="CANCEL" action="{!cancel}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Student Details">
<apex:pageBlockSectionItem >
<apex:outputLabel value="Student Name"/>
<apex:inputText value="{!Sname}" />
</apex:pageBlockSectionItem><br/>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Contact Number"/>
<apex:inputText value="{!Snumber}"/>
</apex:pageBlockSectionItem><br/>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Course Name"/>
<apex:inputText value="{!SCourseName}" />
</apex:pageBlockSectionItem><br/>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Trainer Name"/>
<apex:inputText value="{!trainername}"/>
</apex:pageBlockSectionItem><br/>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Date Of Birth"/>
<apex:inputText value="{!dob}"/>
</apex:pageBlockSectionItem><br/>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Qualification"/>
<apex:selectList size="1">
<apex:selectOption itemValue="B-Tech" />
<apex:selectOption itemValue="Diploma" />
<apex:selectOption itemValue="Graduate" />
<apex:selectOption itemValue="MBA" />
<apex:selectOption itemValue="MCA" />
<apex:selectOption itemValue="PG" />
<apex:selectOption itemValue="PHD" />
<apex:selectOption itemValue="Under Graduate" />
</apex:selectList>
</apex:pageBlockSectionItem><br/>
<apex:pageBlockSectionItem >
<apex:outputLabel value="State"/>
<apex:inputText value="{!state}"/>
</apex:pageBlockSectionItem><br/>
<apex:pageBlockSectionItem >
<apex:outputLabel value="City"/>
<apex:inputText value="{!city}"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
public class insert_cc_Class {
// private ApexPages.StandardController controller;
public String city { get; set; }
public String state { get; set; }
public String qualification { get; set; }
public integer dob { get; set; }
public String trainername { get; set; }
public String SCourseName { get; set; }
public integer Snumber { get; set; }
public String Sname { get; set; }
public PageReference cancel() {
return null;
}
public PageReference save() {
Stud__C obj = new Stud__C();
obj.Sname__c = Sname;
obj.Contact_Number__c = String.valueOf(Snumber);
obj.Qualification__c = qualification;
obj.DOB__c = date.ValueOf(dob);
obj.Course_Name__c = SCourseName;
obj.Trainer_Name__c = trainername;
obj.State__c = state;
obj.City__c = city;
Insert obj;
return null;
}
}
this is very complicated way to do it. Do you really need all these "outputLabel, inputText" etc? It's simpler if you use apex:inputField (it'd magically know the field label and whether the field type is text/date/picklist) and it'd let you easily display lookups too.
There are rare situations when you can't do that (need to bypass SF profile field permissions) but it's in "I really know what I'm doing" category. And for these if you can't just display a lookup you need to hand-craft some search + autocomplete solution. There should be lots of examples on net how to create VF+apex search by name functionality.
That's really reiinventing the wheel though. Seriously, consider using <apex:inputField>
public class Stack72386167{
public Contact con {get;set;}
public Stack72386167(){
con = new Contact();
}
public void save(){
insert con;
}
}
<apex:page controller="Stack72386167">
<apex:form>
<apex:pageBlock>
<apex:pageBlockButtons>
<apex:commandButton value="Save" action="{!save}" />
</apex:pageBlockButtons>
<apex:pageBlockSection columns="1">
<apex:inputField value="{!con.Salutation}" /> <!-- picklists -->
<apex:inputField value="{!con.FirstName}" />
<apex:inputField value="{!con.LastName}" />
<apex:inputField value="{!con.AccountId}" /> <!-- lookups
<apex:inputField value="{!con.Birthdate}" /> <!-- dates (and of course right field labels picked for "free", admin can change them without code changes -->
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

want to display the text based on click on the checkbox in vf page

want to display text in filed based onclick of checkbox in VF page.but the same checkbox is calling one method.
code is bellow....please write controller. need urget help..
<apex:outputPanel id="jobPanel">
Try the code below
Apex Class:
public class Test
{
public Boolean isChecked { get; set; }
public String myText{get;set;}
public void controllerMethod()
{
myText = 'Your Text field rendered';
//assign text field values
}
}
Visualforce Page:
<apex:page controller="Test" >
<apex:form >
<apex:pageBlock id="jobBlock">
<apex:inputCheckbox id="inche" value="{!isChecked}" >
<apex:actionsupport event="onclick" action="{!controllerMethod}" rerender="jobPanel" />
</apex:inputCheckbox>
<apex:outputPanel id="jobPanel">
<apex:pageBlockSection rendered="{!isChecked}">
<apex:pageblockSectionItem >
<apex:inputText value="{!myText}"/>
</apex:pageblockSectionItem>
</apex:pageBlockSection>
</apex:outputPanel>
</apex:pageBlock>
</apex:form>
</apex:page>
Hope it helps you

Having trouble passing a variable to a flow on reRender after clicking submit button

I am trying to pass a variable from in through a Flow. I am new to VisualForce pages so please excuse my ignorance.
I have attached the code below for the controller and VisualForce page.
VF Page
<apex:page controller="testController">
<apex:form>
<apex:inputText value="{!inputValue}" id="textInput" />
<apex:commandButton action="{!actionMethod}" reRender="myFlow" value="GO"/>
</apex:form>
<apex:variable var="input" value="Hello1" />
<flow:interview name="testFlow" id="myFlow">
<apex:param name="inputFromVF" value="{!inputValue}" />
<apex:outputText value="{!inputValue}" />
</flow:interview>
</apex:page>
Apex Class
public class testController{
public Flow.Interview.testFlow myFlow {get; set;}
public testController() {
public PageReference actionMethod() {
return null;
}
public String inputValue { get; set; }
}
When I click the button to refresh the variables the output text refreshes but it doesn't accept the variable value in the parameter. I can hard code something in and it passes it through.
I have figured out a solution after sleeping on it for the night. I set the flow as unrendered when the VF page is first ran and then I render it with the new variable and it works. It is always the easy answers.
The code is below.
VF Page
<apex:page controller="testController">
<apex:form >
<apex:inputText value="{!inputValue}" id="textInput" />
<apex:commandButton action="{!actionMethod}" value="GO" reRender="flowPanel, myFlow">
</apex:commandButton>
</apex:form>
<apex:outputPanel id="flowPanel" rendered="true">
<apex:variable var="input" value="{!inputValue}" />
<apex:outputText value="{!inputValue}" />
<flow:interview name="testFlow" id="myFlow" rendered="{!renderOrNot}">
<apex:param name="inputFromVF" value="{!inputCti}" id="parameter" />
<apex:outputText value="{!inputCti}" />
</flow:interview>
</apex:outputPanel>
Apex Controller
public class testController{
public String inputValue { get; set; }
public Boolean renderPanel { get; set; }
public String inputCti { get; set; }
public Boolean renderOrNot { get; set; }
public Flow.Interview.testFlow testFlow {get; set;}
public String actionMethod() {
renderOrNot = true;
inputCti = inputValue;
return null;
}
}

Resources