You need to sign in to do that
Don't have an account?

Data is not committed to the Database using custom controller
I wrote a custom controller(Wizard based) and two VF pages.
My Intention is to capture the details of custom object(Candidate)Using first page I and
Using Next page I am displying the same fields and save button.
But the records are not saving and not displaying in the VF2.
Controller:
My Intention is to capture the details of custom object(Candidate)Using first page I and
Using Next page I am displying the same fields and save button.
But the records are not saving and not displaying in the VF2.
Controller:
Apex Controller: public with sharing class CanrecordCon { public Candidate__C Can{ get; private set; } public CanrecordCon() { Id id = ApexPages.currentPage().getParameters().get('id'); if(id == null) new Candidate__C(); else Can=[SELECT Name, Phone__C FROM Candidate__C WHERE Id = :id]; } public PageReference Next() { return Page.newCanrecord1; } public PageReference save() { try { insert(Can); } catch(System.DMLException e) { ApexPages.addMessages(e); return null; } // After Save, navigate to the default view page: return (new ApexPages.StandardController(Can)).view(); } } Vf-page1: <apex:page Controller="CanrecordCon" > <apex:form > <apex:pageBlock mode="edit"> <apex:pageMessages /> <apex:pageBlockSection > <apex:inputField value="{!Can.name}" id="No1"/> <apex:inputField value="{!Can.Phone__c}" id="No2"/> </apex:pageBlockSection> <apex:pageBlockButtons location="bottom"> <apex:commandButton value="Next" action="{!Next}"/> </apex:pageBlockButtons> </apex:pageBlock> </apex:form> </apex:page> Vf page2: <apex:page controller="CanrecordCon" tabstyle="Account"> <apex:form > <apex:pageBlock > <apex:pageBlockSection title="Details" collapsible="false" columns="2"> <apex:outputField id="a1" value="{!Can.Name}"/> <apex:outputField id="a3" value="{!Can.Phone__c}"/> </apex:pageBlockSection></apex:pageBlock> <apex:commandButton value="Save" action="{!save}"/> </apex:form> </apex:page>
<apex:page Controller="CanrecordCon" >
<apex:form >
<apex:pageBlock mode="edit">
<apex:pageMessages />
<apex:pageBlockSection >
<apex:inputField value="{!Can.name}" id="No1"/>
<apex:inputField value="{!Can.phone__c}" id="No2"/>
</apex:pageBlockSection>
<apex:pageBlockButtons location="bottom">
<apex:commandButton value="Next" action="{!Next}"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
public class CanrecordCon {
Group_1__c Can;
public group_1__c getCan() {
if(can == null)
can = new Group_1__c ();
return can;
}
public PageReference Next()
{
return Page.newCanrecord1;
}
public PageReference save() {
try {
insert(Can);
} catch(System.DMLException e) {
ApexPages.addMessages(e);
return null;
}
// After Save, navigate to the default view page:
return (new ApexPages.StandardController(Can)).view();
}
}
page 2:
---------
<apex:page controller="CanrecordCon" tabstyle="Account"> <apex:form > <apex:pageBlock > <apex:pageBlockSection title="Details" collapsible="false" columns="2"> <apex:outputField id="a1" value="{!Can.Name}"/> <apex:outputField id="a3" value="{!Can.phone__c}"/> </apex:pageBlockSection></apex:pageBlock> <apex:commandButton value="Save" action="{!save}"/> </apex:form> </apex:page>
All Answers
Additionally, you could get by combining both of these VF pages into 1 VF page. To do this you would render one pageBlockSection for the initial load of the page, and then a second pageBlockSection for the output portion of the page.
I tried with your code( with rerender Attibute) but still same problem.
Thanks
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_quick_start_wizard.htm
Thanks
shashi
Thank you.
<apex:page Controller="CanrecordCon" >
<apex:form >
<apex:pageBlock mode="edit">
<apex:pageMessages />
<apex:pageBlockSection >
<apex:inputField value="{!Can.name}" id="No1"/>
<apex:inputField value="{!Can.phone__c}" id="No2"/>
</apex:pageBlockSection>
<apex:pageBlockButtons location="bottom">
<apex:commandButton value="Next" action="{!Next}"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
public class CanrecordCon {
Group_1__c Can;
public group_1__c getCan() {
if(can == null)
can = new Group_1__c ();
return can;
}
public PageReference Next()
{
return Page.newCanrecord1;
}
public PageReference save() {
try {
insert(Can);
} catch(System.DMLException e) {
ApexPages.addMessages(e);
return null;
}
// After Save, navigate to the default view page:
return (new ApexPages.StandardController(Can)).view();
}
}
page 2:
---------
<apex:page controller="CanrecordCon" tabstyle="Account"> <apex:form > <apex:pageBlock > <apex:pageBlockSection title="Details" collapsible="false" columns="2"> <apex:outputField id="a1" value="{!Can.Name}"/> <apex:outputField id="a3" value="{!Can.phone__c}"/> </apex:pageBlockSection></apex:pageBlock> <apex:commandButton value="Save" action="{!save}"/> </apex:form> </apex:page>