+ Start a Discussion

Getting null value for the varible

<apex:page standardController="Emp__c"  sidebar="false" extensions="EmpPage">
 <apex:form >
 <apex:pageMessages ></apex:pageMessages>
 <apex:pageBlock title="Employee Edit">
 <apex:pageBlockButtons >  <apex:commandButton value="Save" action="{!saveRecordvalues}" immediate="true" />
  <apex:commandButton value="Cancel"/>
 <apex:pageBlockSection columns="1" title="Information">
  <apex:pageBlockSectionItem > Employee Name : <apex:inputField value="{!proxyObject.Name}"/></apex:pageBlockSectionItem>
  <apex:pageBlockSectionItem >  Emp No : <apex:inputField value="{!proxyObject.Emp_No__c}"/> </apex:pageBlockSectionItem>
  <apex:pageBlockSectionItem >    Salary : <apex:inputField value="{!proxyObject.Salary__c}"/>   </apex:pageBlockSectionItem>
  <apex:pageblockSectionItem >Department : <apex:inputField value="{!proxyObject.Dept__c}"/> </apex:pageblockSectionItem>


public class EmpPage {
    public String retURL;
    public EmpPage(ApexPages.StandardController controller) {
    public Emp__c e {set; get; }
    public Emp__c getProxyObject()
     if ( e == null)
      e = new Emp__c();
      return e;
      return e;
    public void saveRecordvalues()
     System.debug('*******I am in try Block*********');

     if( e!= null && e.Dept__c != null)
      Emp__c e1= new Emp__c();
      e1.Name = e.Name;
      e1.Salary__c = e.Salary__c;
      Dept__c ls = [select Id from Dept__c where Name =: e.Dept__c limit 1];
      e1.Dept__c = ls.Id;
      e1.Emp_No__c = e.Emp_No__c;
      insert e1;
      System.debug('***********Record Inserted Successfully***************');
     catch(Exception e)
      apexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Problem Saving Record into object' +e));


When ever i clicking on the button am getting null value to the "e" variable am not able to save the record. Can any one tell me wht mistake am doing in vf page.

Santosh KumbarSantosh Kumbar

Try adding Object e initialize [e = new Emp__c();] in constructor.





Yes, do what San.k said, but also remove your getProxyObject method and refer to the object itself instead. Using that is a little redundant.