You need to sign in to do that
Don't have an account?
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???
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).
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 !!!
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!