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.

  • I'm interested in seeing the answer to this too. I recall trawling through the Force.com ID schema browser in the past looking for it, but was unable to find it. – David Gillen Aug 7 '12 at 15:13
  • Can you provide a little more detail on what isn't working? We have custom objects referencing Person Accounts by doing lookups to Accounts, filtered by "Is Person Account" and record types. I haven't tried linking our PAs to Visualforce pages yet, though. – Mike Chale Aug 7 '12 at 15:30

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".

  • Could you populate that into a custom field, maybe via trigger when a new PA is created? – Mike Chale Aug 7 '12 at 15:49
  • You would probably have to do it after the insert so the Id exists, but I don't see why that wouldn't work. – Nalum Aug 7 '12 at 16:02

Using the Schema Builder, I see the Account object has a "Person Contact" field, that is a Lookup(Contact). That is the only filed I see that seems to reference Person Accounts.

Edit: Double-clicking on that field shows the field name to "Person_Contact".

  • Do you know the API name of this field? I think that's what needed for @Nalum's merge fields. – ca_peterson Aug 7 '12 at 15:29
  • 1
    All it shows is the field name being "Person_Contact". – Mike Chale Aug 7 '12 at 15:32
  • This does not exist in the merge fields. Tough I may be able to use it in the Apex code. Will check that now. – Nalum Aug 7 '12 at 15:34

I had an issue accessing this field, I solved it by creating a formula field on the account object to show it - the formula was simply PersonContact.Id

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.