1

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

9
  • Somebody please help ..I am a newb to this May 20, 2015 at 14:20
  • 3
    You can sidestep the problem for now by using <apex:inputField value="{!Account.name}" required="true"/> which will force all users to enter the required Account name value before the insert is done.
    – Keith C
    May 20, 2015 at 14:21
  • @keithC - Even after making the change.;.I am getting the same error.. the code was woe=rking fine below..but by mistake i removed somethign from the apex class and not its giving an errror May 20, 2015 at 14:23
  • If you are working in eclipse you can get the old instance from the history. it is good if you can post the current error you are comming across
    – Suresh
    May 20, 2015 at 14:29
  • i am not working on Eclipse..@suri Error is "System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Account Name]: [Account Name]" May 20, 2015 at 14:32

1 Answer 1

3

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .