You need to sign in to do that
Don't have an account?
JackOdell
Can you convert an Account to a Person Account via a Trigger?
Hey folks.
Is it possible to convert an Account to a Person Account via a Trigger? Or are Batch Apex and Data Loaders the only way?
The Premiere Customer Support team was able to help me out. As it turns out, there's a couple of hoops you need to jump through to make this work in the context of a trigger. Here's some sample code:
All Answers
Could an @future method do it?
Yes, you should make an update to the account including ONLY the ID of the account and the corresponding RecordTypeId.
I'm getting all sorts of errors which indicate this cannot be done.
Can you indicate in which trigger context that update worked for you? Also, could you provide some sample code?
Here is sample code I whipped up based on your comment which throws an error.
Well, that code looks correct. What mistake throws?
System.DmlException: Update failed. First exception on row 0 with id 001n0000001xsFfAAI; first error: INVALID_PERSON_ACCOUNT_OPERATION, account cannot be converted to person-account: []: Trigger.PersonAccountTester: line 12, column 1
Ahh, I found your problem. It has a circular reference Update on the account.
Change the trigger event to "before update" and do not update the account at end.
Doing it that way throws a different error (see below). Are you 100% sure that you've converted an Account to a PersonAccount in a trigger? Or are just guessing? :-) If you have, please post your code.
Apex trigger PersonAccountTester caused an unexpected exception, contact your administrator: PersonAccountTester: data changed by trigger for field Record Type ID: value not valid for the entity: Account
Well I'm trying to help.
There is another problem to make this conversion in a trigger. As I indicated above the conversion will be successful only if you modify the field RecordTypeId. In a trigger instead is vulnerable to changes in the user enter other fields. I recommend you pass the Id of the account to a future method to perform the update specified.
The Premiere Customer Support team was able to help me out. As it turns out, there's a couple of hoops you need to jump through to make this work in the context of a trigger. Here's some sample code: