0

Im not able to save the standard object account using Extensions by over-riding the SAVE method Help me out guys
Thnks in advance


I'm getting this Error :

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 '{!savenow}' in component in page samplepage: Class.sampleExtension.savenow: line 19, column 1

Class.sampleExtension.savenow: line 19, column 1

Extension ::

public with sharing class sampleExtension { 

public String Type{get;set;}
public String Name{get;set;}
public String Region{get;set;}
public account acc = new account();

public sampleExtension(ApexPages.StandardController controller) {

}

    public PageReference savenow() {

    acc.Name = Name;

    acc.Type= Type;
    acc.Region__c= Region;
system.debug('name'  + acc.name + 'Type'  + acc.Type + 'Region'  + acc.Region__c  );
    insert acc;

    System.debug('nickName: '+Type);

    return null;
}

}

VF Page ::

<apex:page standardController="Account" extensions="sampleExtension" >    
    <p/>
<apex:form >

    <apex:inputField value="{!account.Name}"/> <p/>
     <apex:inputField value="{!account.Type}"/> <p/>
      <apex:inputField value="{!account.Region__c}"/> <p/>
    <apex:commandButton value="Save" action="{!savenow}"/>

</apex:form>

2
  • let me guess: you don't set any Name to your account?
    – Novarg
    Commented Jan 19, 2015 at 15:56
  • There's no issue with your override of the Save button - you aren't supplying a Name on the Account record. Set required="true" on your first input field and this problem should go away.
    – user735
    Commented Jan 19, 2015 at 16:47

1 Answer 1

0

First of all there is no need to create separate variables for assigning values to new record i.e. Name, Type, Region etc if you are using inputfield on vf page.

Initiate "account" variable in constructor and declare that as getter/setter. Hope this works.

You must log in to answer this question.

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