• jimmmijammin200
  • 0 Points
  • Member since 2008

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
  • 1
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
//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;
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
  • December 11, 2008
  • Like
  • 0