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
MachhiMachhi 

Contact record for person account update error

I have person accounts enabled for my organization.

 

I am trying to update a contact record. When I execute update query and if the contact record is my person account, it throws me below error:

 

INVALID CROSS REFERENCE KEY

Cannot select a person account.

 

I can understand that the contact record is actually referring to person account .. but then why should I able to select it using - select id from contact where id = 'personaccountid'?  

 

 

If anybody knows the resolutions, please do let me know.

 

 

Regards,

Chandrakant M

sfdcfoxsfdcfox

In the newer APIs, the Contact is completely read-only if it is attached to an account (as in, a Person Account). Instead, use the same field on the account, and update that instead.

 

Review the following:

// You can't do this...
Contact c = [select id,firstname,lastname,email,email2__c from contact where id = :someid];
c.email2__c=theNewEmail; // this is a string variable.
update c; // Oops! This is a person account...

// Instead, modify the record at the account level...
Account a = [select id,personfirstname,personlastname,personemail,email2__pc from account where personcontactid = :someid];
a.email2__pc=theNewEmail;
update a; // This works!

You should use a Person Account the same as you would a regular account--the contact record is only a "convenience" for the underlying data model and does not reflect how a developer should access the data. In the latest versions of the API, you must make any and all changes to a person account through the account, not the contact.
GhilliGhilli

Hi All,

 

The above one is a good option to update a person account.

 

But tell me how to seperate the person account from the contacts.

I need to query all the existing contact records from the system and want to update a field in the contact record.

While bulk updating these contact records its throwing error like "bad invalid field" like that.

When i try to access the error line its specifying the person account record which dont have the field which i am updating in the contact.

 

Please tell me how to seperate this person account so that i can update only contact records.

 

Thanks,

Ghilli.

sfdcfoxsfdcfox

You can filter out those contacts using a query similar to the following:

 

SELECT Id,... from Contact WHERE IsPersonAccount = FALSE

 

This will return only contact records that you can update (assuming security permissions, not locked for pending updates, etc).