function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
FengFeng 

HOW TO: Convert existing contact to person account???

we just enabled person account on the contact object, but there are lots of existing contacts do not have any 1 to 1 person account on account object,
 
Is there any way to create person accounts for these existing contact without deleting these contacts, as these contacts were referenced by different objects;
 
here is my code trying to do: the record type in account is updated successful, but is IsPersonAccount is field in Account is still set to false
 
Code:
//get the business account record type
RecordType NotPersonAccountRecordType = [select Id, Name, SobjectType,
         IsPersonType from RecordType where SobjectType='Account'
         and IsPersonType=False];

// get 1 existing account
Contact c = [select id, AccountId, FirstName, LastName, Cris_Id__c from Contact where IsPersonAccount = false Limit 1];


// create a new account and set the record type to business account
Account newAccount = new Account();
newAccount.Name='' + c.LastName;
newAccount.RecordTypeId = NotPersonAccountRecordType.Id;
insert newAccount;


//get the person account record type
recordType personaccountrecordtype = [select Id, Name, SobjectType,
         IsPersonType from RecordType where SobjectType='Account'
         and IsPersonType=True];

// update the existing contact's account to new account
c.AccountId = newAccount.Id;
update c;


// now get it again and update the firstname and lastname, change the record type to person account
newAccount = [select id,lastName, Firstname, RecordTypeId from Account where Id =: newAccount.Id];
newAccount.RecordTypeId = personaccountrecordtype.Id;
newAccount.LastName=c.LastName;
newAccount.FirstName=c.FirstName;   
update newAccount;

These code runs successfully, but the IsPersonAccount in Account object is false for some reason

Any one have idea how to get around the problem or other direction to do these?


thanks in advance


 


Message Edited by Feng on 12-10-2008 05:57 PM

Message Edited by Feng on 12-10-2008 05:59 PM
Best Answer chosen by Admin (Salesforce Developers) 
Feng_WFeng_W

Hi, Ron, i had to change my name login to get my password :(

 

we work around  this problem by creating a CSharp application to convert them into personal account

 

"The record type can only be changed via the API, using a tool like Data Loader or the Excel Connector"

 

please go these website for more details

http://www.x2od.com/2008/08/19/convert-between-business-and-person-accounts-b2b-b2c.html

 

Hope that helps

 

Feng

 

All Answers

jimmmijammin200jimmmijammin200
http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_guidelines_personaccounts.htm
"If you change the record type of a business account to a person account using either update() or upsert(), you cannot make any other changes to fields in that account in the same call; if attempted, the fault INVALID_FIELD_FOR_INSERT_UPDATE will result. However, you can change record type values from one person account record type to another, or from one business account record type to another, in the same call with other changes. "
 
"When converting a business account to a person account, there must be a one-to-one relationship between each business account record and its corresponding contact record. Furthermore, fields common to both records such as Owner and Currency must have identical values. "
 
It would seem from the above points, that you do not create a new contact or account record manually. If you do an update to the record type manually, the system will convert the records automatically (where common fields overlap)?
 
From your first statement, these orphan contacts must belong to an account before they can be converted.
Ron WildRon Wild

Feng, did you ever figure this one out?   I'm running into the same problem:

 

Have created one account and one related contact.

 

Tried to change the record type to a person account record type.

 

The operation succeeds (record type id is changed) but the contact and account are still separate entities (also,  trying to view the account produces an error)

 

Here is the code I ran from the Execute Anonymous window in Eclipse (sandbox account) to test the conversion:

 

 

Contact newContact = new Contact( firstname= 'Bob', lastname='Test', email = 'bob@test.com'); insert newContact; Account newAccount = new Account (name = 'Bob Test'); insert newAccount; newContact.accountId = newAccount.Id; update newContact; //get the person account record type RecordType personaccountrecordtype = [select Id, Name, SobjectType, IsPersonType from RecordType where SobjectType='Account' and IsPersonType=True]; Account[] convertAccounts = [Select id, RecordtypeId from Account where Id = :newAccount.Id ]; convertAccounts[0].RecordTypeId = personaccountrecordtype.Id; convertAccounts[0].LastName = newContact.lastname; System.debug(Database.update(convertAccounts));

 

 ... and the error Salesforce shows when trying to view the account created above:

 

 

An internal server error has occurred An error has occurred while processing your request. The salesforce.com support team has been notified of the problem. If you believe you have additional information that may be of help in reproducing or correcting the error, please contact support@salesforce.com. Please indicate the URL of the page you were requesting, any error id shown on this page as well as any other related information. We apologize for the inconvenience. Thank you again for your patience and assistance. And thanks for using Salesforce! Error ID: 2092721332-769 (-328500233)

 

 

 

 

Feng_WFeng_W

Hi, Ron, i had to change my name login to get my password :(

 

we work around  this problem by creating a CSharp application to convert them into personal account

 

"The record type can only be changed via the API, using a tool like Data Loader or the Excel Connector"

 

please go these website for more details

http://www.x2od.com/2008/08/19/convert-between-business-and-person-accounts-b2b-b2c.html

 

Hope that helps

 

Feng

 

This was selected as the best answer
Ron WildRon Wild

Just an update for anyone following this thread .... we've implemented both a batch Apex convert to person account solutioni as well as on-click javascript buttons that users can click to convert individual account/contact pairs to person accounts.  (note: the account/contact pairs meet SF's requirements for conversion (identical values in fields shared between accounts and person_contacts):

 

Here's the javascript code:

 

 

{!REQUIRESCRIPT("/soap/ajax/17.0/connection.js")}
var ready = true;
if ({!Account.pymt__Convert_To_Person_Account__c } == false) {
ready = false;
alert('This account has not been set up for person account conversion. Please make sure this account has been paired with a single Contact record (with the same name) and "Convert To Person Account" is checked.');
}
if(ready && confirm("Are you sure you want to convert this Account and Contact to a single Person Account? This is NOT reversible.")) {
varAccountObj = new sforce.SObject("Account");
AccountObj.Id = "{!Account.Id}";
AccountObj.RecordTypeId = "012xxxxxxxxxxxx";
msg = sforce.connection.update([AccountObj]);
alert(msg);
location.reload(true);
}

 

 

Just replace the "012xxxxxxxxxxxx" with the record type id for a person account in your SF org.

 

 

 

 

Dennis W.Dennis W.

Can you help me with the code for a button on a Contact detail page to convert a contact without an acccount to a person account?

 

And will it work if there is no account yet, only a contact?