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:
While the following code produced the exact error you got:
Double-check to make sure that you are using a record type that is valid for your profile, and has IsPersonType set to true.