I have a use case whereby I'm trying to convert an Account generated from the LiveChat pre-chat API into a Person Account. Some sample code is as follows. Note the Record Type names are arbitrary, with Generic representing an Account RT which corresponds to Business Accounts and Person_Account_RT corresponding to Person Accounts.

Account act = new Account();
act.Name = 'foobar';
act.ChatEmail__c = 'foo@bar.com';
act.ChatFirstName__c = 'foo';
act.ChatLastName__c = 'bar';
act.RecordTypeId = getAccountRecordType('Generic').Id;
insert act;

Contact con = new Contact();
con.FirstName = 'foo';
con.LastName = 'bar';
con.Email = 'foo@bar.co';
con.RecordType = getContactRecordType('Person_Account_RT');
con.AccountId = act.Id;
insert con;

act.RecordType = getAccountRecordType('Person_Account_RT');
update act;

act = [SELECT Id, IsPersonAccount, RecordType.Id FROM Account WHERE Id = :act.Id LIMIT 1];


In this design I get no exception, but the Record Type is not set on the account and it does not convert to a Person Account.

If I change to use RecordTypeId instead as follows:

act.RecordTypeId = getAccountRecordType('Person_Account_RT').Id;
update act;

I am getting the following exception: System.DmlException: Update failed. First exception on row 0 with id 0010r00000ByjDiAAJ; first error: INVALID_FIELD_FOR_INSERT_UPDATE, Cannot specify any additional fields when marrying or separating a Person-Account: []


The second code is closer to be accurate, but you "can't specify additional fields", so you actually need to do something like this:

Account convertToPersonAccount = new Account(
update convertToPersonAccount;
act = [SELECT Id, IsPersonAccount, RecordType.Id FROM Account WHERE Id = :act.Id];
| improve this answer | |
  • Oh @sfdcfox, you are my bae! – Shane Nov 19 '19 at 12:55

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.