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 {
        System.debug( '\r\nJust created lead: ' + lead.id + '\r\n');
        //Now if set, create campaign member record.
        cm.LeadId = lead.Id;
        cm.Status = '1';
        try {
        catch(Exception e){
            //exception code here
        PageReference secondPage = new PageReference(
                ApexPages.currentPage().getParameters().get('retUrl') );
        System.debug( ' about to redirect to: ' +
        return secondPage;
    catch(System.DMLException e) {
        //notify admin code here         
        PageReference secondPage = new PageReference('/apex/InsertFail?m=' + e  );
        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"/>

        <apex:outputLabel value="*Last Name" for="LastName"></apex:outputLabel>
        <apex:inputField required="false" value="{!Lead.LastName}" id="LastName"/>

        <apex:outputLabel value="*Home Phone" for="HomePhone"></apex:outputLabel>
        <apex:inputField required="false" value="{!Lead.Home_Phone__c}" id="HomePhone"/>


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

Does anyone have any suggestions?

  • Welcome to SFSE, hgolov. – Mike Chale Jul 14 '13 at 19:04

I have had similar problems many times in the past. It would be worth looking into whether there is any page-level validation "silently" failing which would prevent the save method in your controller being hit:

  1. Add an <apex:pageMessages/> somewhere in your page just in case there are some hidden page messages that may be relevant.
  2. Add something like "System.assert(false)" in the first line of your save method in the controller. If this method is successfully being hit then you will get a Visualforce exception when you click the save button which will help you determine whether this method is running or not.
  3. Use the developer console to generate a debug log for when you click the save button. Search the log for tokens such as "exception", "error" etc.
  • Thank you! Adding a page message did the trick - I was attempting to set a date field in javascript with the value {!Now}, but it was the wrong format. – hgolov Jul 15 '13 at 6:04

You've only shown us part of your Visualforce page, but I don't see where you've set the retUrl parameter your controller is expecting (see the below excerpt of your code):

PageReference secondPage = new PageReference(ApexPages.currentPage().getParameters().get('retUrl') );
     System.debug( ' about to redirect to: ' +ApexPages.currentPage().getParameters().get('retUrl'));
     return secondPage;
  • Sorry, I left that part out. But I had debugged with a javascript alert and seen that it was set correctly. I also debugged that in the controller and saw that. – hgolov Jul 15 '13 at 6:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.