1

I am trying to assign value to compound field(FirstName) for specific record type. But got an error. "System.DmlException: Insert failed. First exception on row 0; first error: INVALID_FIELD_FOR_INSERT_UPDATE, Account: bad field names on insert/update call: FirstName: [FirstName]".

Account acc = new Account(RecordTypeId = '012Hr000001JoSAIA0', FirstName= 'first name');
insert acc;

But for other record types I can assign value to compound field.

1 Answer 1

0

The Last Name field is always required when creating a contact. If you don't provide a Last Name, you can't use First Name.

Example code that works:

insert new Account(FirstName='Brian', LastName='Fear');

Note that you don't necessarily need to provide the RecordTypeId; Salesforce will just use the user's default Person Account Record Type.

2
  • I have multiple record types of Account. But I want to create Record of specific record Type. That's why I am using RecordTypeId in creating record. My question is Why I cannot access this compound fields during record creation. Commented Apr 2 at 11:40
  • @MuhammadJahanzaibTariq The last name field is required to create a person account. I also only said that the record type Id is optional if you don't mind the default record type.
    – sfdcfox
    Commented Apr 2 at 13:12

You must log in to answer this question.

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