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
bluecapbluecap 

Need to return Person Accounts related to an Account with SOQL

Im struggling with the syntax for pulling out the Person Accounts related to the Account. Any ideas what I am doing incorrectly?

Select a1.Name, a1.Person_Parent_Account__c, (Select Person_Parent_Account__r.PersonEmail, Person_Parent_Account__r.PersonHomePhone, Person_Parent_Account__r.PersonMobilePhone, Person_Parent_Account__r.PersonMailingLongitude, Person_Parent_Account__r.PersonMailingLatitude, Person_Parent_Account__r.PersonMailingCountry, Person_Parent_Account__r.PersonMailingPostalCode, Person_Parent_Account__r.PersonMailingState, Person_Parent_Account__r.PersonMailingCity, Person_Parent_Account__r.PersonMailingStreet, Person_Parent_Account__r.FirstName, Person_Parent_Account__r.LastName From Accounts)
from Account a1
where a1.ID = {!acct.Id}
Best Answer chosen by bluecap
ShashForceShashForce
Hi,

You must include the "IsPersonAccount" field in your SOQL to be able to use the personAccount fields on the Account object. Somethig like this:

Select a1.Name, a1.Person_Parent_Account__c, (Select Person_Parent_Account__r.isPersonAccount, Person_Parent_Account__r.PersonEmail, Person_Parent_Account__r.PersonHomePhone, Person_Parent_Account__r.PersonMobilePhone, Person_Parent_Account__r.PersonMailingLongitude, Person_Parent_Account__r.PersonMailingLatitude, Person_Parent_Account__r.PersonMailingCountry, Person_Parent_Account__r.PersonMailingPostalCode, Person_Parent_Account__r.PersonMailingState, Person_Parent_Account__r.PersonMailingCity, Person_Parent_Account__r.PersonMailingStreet, Person_Parent_Account__r.FirstName, Person_Parent_Account__r.LastName From Accounts where Person_Parent_Account__r.isPersonAccount = true)
from Account a1
where a1.ID = {!acct.Id}

If this answers your question, please mark this as the Best Answer for this post, so that others can benefit from this post.

Thanks,
Shashank