ID for Contact portion of Person Account

Is it possible to get the ID of a Contact which is part of a Person Account?

I have a custom object which has a custom field referencing the Person Account, though it seems to be referencing the Contact directly. I have created a button which I am using to pass the ID into a Visualforce Page.

With the Insert Field drop-down on the create/edit button page I can put in {!Account.Id} or {!Contact.Id} but neither of these work. The Account ID is placed in the URL but is not the correct ID and the Contact ID is blank, which I assume is because the button is on a Person Account page and not a Contact Page.

Answer

I Up-voted Mike Chale as he pointed me in the right direction.

To get this to work I use the Account.Id to get the Account.PersonContactId which is then used in my Custom Object.

Account a = [Select PersonContactId From Account Where Id = :AccountId];
CustomObject co = [Select Name From CustomObject Where Client__c = :a.PersonContactId];

There doesn’t seem to be a way to get this value in the Merge Field drop-down list on the create/edit button page.

A list of all person account fields can be found in the documentation. Scroll 2/3 down the page to the section titled “IsPersonAccount Fields”.

Attribution
Source : Link , Question Author : Nalum , Answer Author : Daniel Hoechst

Leave a Comment