+ Start a Discussion

Inserting account field in visual force page having Person Accounts Record types

Error message while updating Person Account through visual force wizard

 herei s my code 



<apex:page controller="patientController" tabStyle="Opportunity" sidebar="false" showHeader="false">
<apex:form >
<apex:pageBlock title="Record Type">
<apex:pageMessages />
<apex:pageblocksection >
<apex:panelGrid >
<apex:outputLabel value="Record Type" for="recordtype"/>
<apex:inputField id="recordtype" value="{!PersonAccount.RecordTypeId}"/>



<apex:pageBlockSection title="Contact Information">
<apex:panelGrid columns="2">
<apex:outputLabel value="Name" for="perfirstName"/>
<apex:inputField id="perfirstName" value="{!PersonAccount.Name}"/>

<apex:facet name="footer">
<apex:outputPanel >
<apex:commandButton action="{!step1}" value="Next" styleClass="btn"/>





Class.patientController.save: line 70, column 1     



while inserting the Person account error is 


System.DmlException: Insert failed. First exception on row 0; first error: INVALID_FIELD_FOR_INSERT_UPDATE, Account: bad field names on insert/update call: Name: [Name]

Error is in expression '{!save}' in component <apex:page> in page docinfopage


Any one please need a suggestion 


 public PageReference save() {   

insert PersonAccount;

PageReference orderPage = new PageReference('/' +PersonAccount.id);

return orderPage;



Thanks In advance,

Newbie @ knight12

Shailesh DeshpandeShailesh Deshpande
I am not sure but I think you probably need to use firstName and lastName fields instead of Name field. Secondly, you might also need to set isPersonAccount field to true.

With person Account you should be inserting values for firstname and last name,then only you can perform insert operation for any record.