2

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

I am facing above error:

Account acc = new Account();
if(nameParts[0] != null)
    acc.FirstName=nameParts[0];
if(nameParts[1] != null)
    acc.LastName=nameParts[1];

acc.PersonEmail=caseObj.SuppliedEmail;                         
acc.Phone = caseObj.SuppliedPhone;
acc.recordTypeId = personAccountRecordType.Id;
  • 1
    What does contain your nameParts array? Did you activate the person account record type? – Martin Lezer Apr 5 '17 at 15:50
  • Combination of First Name and LastName, Both values are present – user4567570 Apr 5 '17 at 15:52
  • Please use System.debug() on the nameParts array to check the values. – Martin Lezer Apr 5 '17 at 15:55
  • 1
    I think LastName or FirstName or both coming as blank from array parsing, thats why the error is – Santanu Boral Apr 5 '17 at 15:57
5

You're using the wrong record type. I verified that if you were using the correct record type, you would not receive this error. The following code works in my developer org in execute anonymous:

Id rtId = [SELECT Id FROM RecordType WHERE IsPersonType = TRUE AND SObjectType='Account' LIMIT 1].Id;
Account a = new Account(RecordTypeId=rtId);
a.FirstName = 'Test';
a.LastName = 'Test';
insert a;

While the following code produced the exact error you got:

Id rtId = [SELECT Id FROM RecordType WHERE IsPersonType = FALSE AND SObjectType='Account' LIMIT 1].Id;
Account a = new Account(RecordTypeId=rtId);
a.FirstName = 'Test';
a.LastName = 'Test';
insert a;

Double-check to make sure that you are using a record type that is valid for your profile, and has IsPersonType set to true.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.