[SalesForce] How to troubleshoot when converting an Account to Person Account fails

I'm currently migrating around 2000 accounts to person account via apex. For some reason, it fails on one account. I have checked that it meets all the criteria (one child contact, same owner, same currency, no Parent Account etc..) and it still fails. The logs just say:

System.DmlException: Update failed. First exception on row 316 with id 0011v00001yl1CHAAY; first error: INVALID_PERSON_ACCOUNT_OPERATION, account cannot be converted to person-account: []

Does anyone know a way to get more info about the error?

Best Answer

From Setting Up Person Accounts:

Prepare Business Accounts to be Converted to Person Accounts

Each account and contact that you plan to convert to must meet these conditions.

  1. Each account must have one contact. It can’t have more than one.
  2. The account and contact must have the same record owner.
  3. The account and contact must have the same currency values.
  4. The Parent Account field on the Account must be blank.
  5. The Reports To field on the Contact must be blank.
  6. The Account is not set as a Parent Account for any other accounts.
  7. The Contact is not set as a Reports To for any other contacts.

You didn't mention steps 5-7 in your post, and in particular 6 and 7 are the most likely to trip people up. Double check that no records look up to either the Account or the Contact via ParentId and ReportsToId, respectively. If you have verified with 100% certainty that each of the above criteria is fulfilled, you need to open a support case.

Here is an anonymous script you could use to verify each step. If it runs successfully, you can share it with support and posit that you have encountered a bug.

Account account = [
    SELECT
        OwnerId, CurrencyISOCode, ParentId,
        (SELECT Id FROM ChildAccounts LIMIT 1),
        (SELECT OwnerId, CurrencyIsoCode, ReportsToId FROM Contacts)
    FROM Account WHERE Id = '001...'
];

system.assertEquals(1,
    account.Contacts.size(),
    'Condition 1 violated');

Contact contact = account.Contacts[0];

system.assertEquals(account.OwnerId,
    contact.OwnerId,
    'Condition 2 violated');
system.assertEquals(account.CurrencyISOCode,
    contact.CurrencyISOCode,
    'Condition 3 violated');
system.assertEquals(null,
    account.ParentId,
    'Condition 4 violated');
system.assertEquals(null,
    contact.ReportsToId,
    'Condition 5 violated');
system.assertEquals(0,
    account.ChildAccounts.size(),
    'Condition 6 violated');
system.assertEquals(0,
    [SELECT count() FROM Contact WHERE ReportsToId = :contact.Id],
    'Condition 7 violated');
Related Topic