Search code examples
salesforceapex-codevisualforceapex

Salesforce visualforce save button doesnt save


I am new to salesforce environment and I am trying to achieve simple thing. I want to create new Lead screen with custom lead questions and save that as a Lead.

I created apex form, overridden new lead button page, but when I press save button on that page, I dont get any error but it also doesnt save the Lead. Cancel button seems to be working.

Do I need to write custom code for save or apex:pageblockbuttons default action should work ?

I will just show short snippet of the code, as most of it is just setting the input fields

<apex:form id="mySection">
    <apex:pageBlock title="New Lead: {!Lead.Name}">

        <apex:pageBlockSection title="Lead information" columns="1" >
            <apex:inputField value="{!Lead.FirstName}" tabOrderHint="1"/>
            <apex:inputField value="{!Lead.LastName}" tabOrderHint="2"/>
<!--  Other fields are skipped  -->
            <apex:inputField value="{!Lead.Project_Value__c}" tabOrderHint="3"/>  
        </apex:pageBlockSection>
        <apex:pageBlockButtons >
            <apex:commandButton action="{!save}" value="Save"/>
            <apex:commandButton action="{!cancel}" value="Cancel" immediate="true"/>
        </apex:pageBlockButtons>           
    </apex:pageBlock>
</apex:form>

Solution

  • I found the solution, which was not related to the apex itself, but more to a one custom field which was mandatory but not on the page. I decided to leave the answer here, because while I was trying to find the solution to this issue, I discovered command which actually shows why the input form failed.

    <apex:pageMessages />
    

    Maybe that is a common knowledge to Visualforce, apex users, but for me it was a helpful tool and thats why I decided to leave it in an answer, if someone will have similar issue to remember to add that line.