[SalesForce] Error while saving the record in apex

my controller is like this

public class newaccountcontroller 
{
    public Account acct{get;set;}

    public newaccountcontroller(ApexPages.StandardController stdController) 
    {
             this.acct = (Account)stdController.getRecord();

    }

    Public pagereference NewAccount()
    {
        Insert acct;
        return null;
    }

    public pagereference cancelButton()
    {
        Pagereference cnclbutton = new Pagereference('/apex/accountdisplay');
        cnclbutton.setredirect(true);
        return cnclbutton;
    }

}

My VF page is like below

<apex:page standardController="account" extensions="newaccountcontroller">
<apex:pageBlock >
<apex:form >
<apex:pageBlockSection >
    <apex:inputField value="{!Account.name}"/>
    <apex:inputField value="{!Account.accountnumber}"/>
    <apex:inputField value="{!Account.type}"/>
    <apex:inputField value="{!Account.industry}"/>
    <apex:inputField value="{!Account.rating}"/>
    Email:<apex:inputText />
</apex:pageBlockSection>
</apex:form>

<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >
        <apex:commandButton value="Save" action="{!NewAccount}"/>
        <apex:commandButton value="Cancel" action="{!CancelButton}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>

</apex:pageBlock>
</apex:page>

I am trying o save the object but i am getting the following error..pls help

error is

System.DmlException: Insert failed. First exception on row 0; first
error: REQUIRED_FIELD_MISSING, Required fields are missing: [Account
Name]: [Account Name] Error is in expression '{!NewAccount}' in
component in page newaccount:
Class.newaccountcontroller.NewAccount: line 13, column 1

Best Answer

The <apex:inputField...> elements and the command buttons should be in the same <apex:form...> container.

Related Topic