function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
VK2009VK2009 

Problem on save for simple Form

My UI will have 2 input box.Unable to save data into DB..Help me out!! 

Here is my vf code:

 

 

<apex:page controller="testapplicationApex">

  <apex:form >

  <apex:pageblock title="Reena Application" mode="edit">

  <apex:pageblockButtons >

  <apex:commandButton value="Save" action="{!save}"/>

  <apex:commandButton value="Cancel" onclick="top.history.go(-1);return false;"/>

  </apex:pageblockButtons>

  <apex:pageBlockSection title="Test Details" Collapsible="false" columns="1">

  <apex:inputField value="{!test.Name__c}"/>

<apex:inputField value="{!test.TNumber__c}"/>

  </apex:pageBlockSection>

  </apex:pageblock>

  </apex:form>

</apex:page> 

 

Controller code:

public class testapplicationApex {

public test__c test{get;set;}

 

public test__c gettest() {

if(test== null) test= new test__c();

return test;

}

public PageReference save(){

try{

if(test== null) test= new test__c();

insert test;

}

catch(System.DMLexception e){

ApexPages.addmessages(e);

return null;

}

PageReference p = Page.app1;

       p.setRedirect(true);

       return p;

}

 

}

 

what needs to change???  

bob_buzzardbob_buzzard

Can you tell us what the exact problem is - do you get an exception or does the data fail to save to the database.

 

(I suspect the latter, looking at the code, but please confirm).

VK2009VK2009

record is getting created(ID) each time  when I click on Save button, but datas(Name & No) are not getting saved into database.

 

Please help me out !!!

S_LieS_Lie

You need to create constructor to define the Test. otherwise everytime you save it , the test always return null value

 

refer to :

if(test== null) test= new test__c();

insert test;

 

Hope it works!