I have a custom controller that has been working for years (literally), and for tens of pages. Basically, the page displays a form with a number of lead fields, and when the user clicks a command button that has an action of the save method in my custom controller, it saves the lead, creates a campaign member, and then redirects the user to a page defined in the visualforce page.
The way we create the vf pages, is usually to find one with similar fields, clone, make the necessary changes, and save.
Today I took a form that was created last week and working well. I cloned and created two more pages, but neither of these pages are acting as expected. When a user (me for now) clicks the submit button, the page just reloads with the same information filled out, and no objects are created.
Controller Code:
public lead_WebFormInsert() {
lead = new Lead();
cm = new CampaignMember();
}
....
public PageReference save() {
try {
insert(lead);
System.debug( '\r\nJust created lead: ' + lead.id + '\r\n');
//Now if set, create campaign member record.
cm.setOptions(dmo);
cm.LeadId = lead.Id;
cm.Status = '1';
try {
insert(cm);
}
catch(Exception e){
//exception code here
}
PageReference secondPage = new PageReference(
ApexPages.currentPage().getParameters().get('retUrl') );
secondPage.setRedirect(true);
System.debug( ' about to redirect to: ' +
ApexPages.currentPage().getParameters().get('retUrl'));
return secondPage;
}
catch(System.DMLException e) {
//notify admin code here
...
PageReference secondPage = new PageReference('/apex/InsertFail?m=' + e );
secondPage.setRedirect(true);
return secondPage;
}
}
VisualForce Code:
<apex:form onsubmit="return doCheckForm()">
<div style='color:red;'>All items marked with a star are required information</div>
<apex:outputLabel value="*First Name" for="FirstName"></apex:outputLabel>
<apex:inputField required="false" value="{!Lead.FirstName}" id="FirstName"/>
<br/><br/>
<apex:outputLabel value="*Last Name" for="LastName"></apex:outputLabel>
<apex:inputField required="false" value="{!Lead.LastName}" id="LastName"/>
<br/><br/>
<apex:outputLabel value="*Home Phone" for="HomePhone"></apex:outputLabel>
<apex:inputField required="false" value="{!Lead.Home_Phone__c}" id="HomePhone"/>
<br/><br/>
...
<apex:commandButton action="{!save}" value="Submit"/>
.....
Does anyone have any suggestions?