[SalesForce] INVALID_FIELD_FOR_INSERT_UPDATE, Account: bad field names on insert/update call: LastName, FirstName: [LastName, FirstName]ge

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;

Best Answer

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.

Related Topic