+ Start a Discussion
Nitish Bharadwaj BNitish Bharadwaj B 

Error in saving the data in a custom object

I had 5 fields in my custom object(My custom object is apex_leave_approval__c),and i tried to insert details in the fields through Visual Force page and save the record.But if I try to do this process using a apex code in the Visual Force page I get only the id in the record of my custom object.Please help me with an answer

This is my code

<apex:page StandardController="apex_Leave_Approval__c" >

  <h1>Leave request App</h1>
  <br/><br/>

   <apex:image url="https://image.shutterstock.com/image-vector/creative-stylish-elegant-connected-industrial-260nw-648984286.jpg" />
  <apex:form id="NitishApp">
  <apex:pageBlock title="Enter the Details Below">
  
        <apex:pageBlockButtons >
        <apex:commandButton value="Save" action="{!save}" immediate="true"/>
        <apex:commandButton value="Cancel" action="{!Cancel}" />
        </apex:pageBlockButtons>
        
          
  <apex:pageBlockSection title="Enter the Details" columns="1">
             <apex:inputField id="Name"   value="{!apex_Leave_Approval__c.name}"  required="true"/>
              <apex:inputField id="ID" value="{!apex_Leave_Approval__c.apex_E_ID__c}" required="true"/>

             <apex:inputField id="Days_of_leave" value="{!apex_Leave_Approval__c.apex_Days_of_leave__c}" required="true"/>

             <apex:inputField id="Type_of_leave" value="{!apex_Leave_Approval__c.apex_Type_of_Leave__c}" required="true"/>

             <apex:inputField id="Approval" value="{!apex_Leave_Approval__c.apex_Approval__c}" required="true"/>
              
  
          </apex:pageBlockSection>
           </apex:pageBlock>
        
       
  </apex:form>

  
</apex:page>




With this code I could save only the Id but not the Actual message in the fields
Jakub Kołodziej 7Jakub Kołodziej 7
Check your field api names. I recreated this object on my dev org and everything is working as expected:User-added image
<apex:page StandardController="apex_Leave_Approval__c" >

  <h1>Leave request App</h1>
  <br/><br/>

   <apex:image url="https://image.shutterstock.com/image-vector/creative-stylish-elegant-connected-industrial-260nw-648984286.jpg" />
  <apex:form id="NitishApp">
  <apex:pageBlock title="Enter the Details Below">
  
        <apex:pageBlockButtons >
        <apex:commandButton value="Save" action="{!save}"/>
        <apex:commandButton value="Cancel" action="{!Cancel}" />
        </apex:pageBlockButtons>
        
          
  <apex:pageBlockSection title="Enter the Details" columns="1">
             <apex:inputField value="{!apex_Leave_Approval__c.name}"  required="true"/>
             <apex:inputField value="{!apex_Leave_Approval__c.apex_E_ID__c}" required="true"/>
             <apex:inputField value="{!apex_Leave_Approval__c.apex_Days_of_leave__c}" required="true"/>
             <apex:inputField value="{!apex_Leave_Approval__c.apex_Type_of_Leave__c}" required="true"/>
             <apex:inputField value="{!apex_Leave_Approval__c.apex_Approval__c}" required="true"/>
                
          </apex:pageBlockSection>
           </apex:pageBlock>   
  </apex:form> 
</apex:page>

 
Jakub Kołodziej 7Jakub Kołodziej 7
Well, seems like "immediate" is causing this bug:
<apex:commandButton value="Save" action="{!save}" immediate="true"/>
<apex:commandButton value="Save" action="{!save}"/>

From documentation: 
Setting immediate=true does not fire getters or setters and skips validation.