You need to sign in to do that
Don't have an account?
Creating Person Account with Apex
I have created a before insert trigger on case that will query Account for the existence of a social security number and if there is no match, a person account is created.
I then update the case with AccountID and PersonContactID (for ContactID).
My problem is that while I can update the case with the AccountID, the PersonContactID is null (also IsPersonAccount is false at this point). When I inspect the new account afterwards, there is a PersonContactID and IsPersonAccount is true.
The code compiles fine and executes fine with no errors doing all it should do except setting the ContactId.
It seems to me that the person account creation is a two step rocket behind the scene. First the account is created, then an internal trigger fires which creates the "shadow contact" and updates the account with the necessary information like the PersonContactID.
Thus my attempt to update the case happens in beteween those two steps. Am I right?
What can I do to work around this fact?
/Mats
I deal with Person Accounts all the time in the Wealth Management / Private Equity space as its a B2C business model.
I haven't run into this problem personally. However, I can offer a few suggestions:
1. After you insert the PersonAccount record, can you then turn around and query the PersonAccounts records you created instead of using the object in memory that you just created. Step A insert PersonAccount as you do today. Step B Turn around and Query for ContactID using the AccountId for the PersonAccount you just created?
2. If suggestion 1 doesn't work, you can create the Account as a Business Recordy Type, and Create the Contact. Then you can convert the Business Account into a PersonAccount. That will have all the records created, both the PersonAccount and its "Shadow" contact which sits behind the scenes.
Thank you for your answer,
I will try out your plan 1.
Plan 2 I have already tried but I ran into problems marrying the two together, something like "INVALID_FIELD_FOR_INSERT_UPDATE, Cannot specify any additional fields when marrying or separating a Person-Account []"
Best regards.
/Mats
Hi,
I have tried your alternative 1, but stumble on s syntax problem.
In my world I have pulled AccountID's and PersonContactId's into the map mAccs which I later query by Key to obtain the PersonContactID. Obiously that is not happening.
What is wrong?
/Mats