Based on some of the answers I've browsed I think this might involve 2 queries. I feel like this is probably a pretty common problem so I was hoping someone would have a quick answer or at least be able to point me to the docs that detail how this works. I briefly looked through relational queries but didn't immediately see anything relevant to this kind of bubbling so I am posing the question here.


There's no direct way of fetching a Parent Id from the Account hierarchy using SOQL. However, if you want to use some Apex, you can do it using the below snippet available in the Inline Account Hierarchy package, where currAcctId is the Child Account for which you need to find the top most Parent Account.

while (!isTopLevelAccount) {
    acct = [select a.Id, a.ParentId From Account a where a.Id = :currAcctId limit 1];
    if (acct.ParentID != null) {
        currAcctId = acct.ParentID;
    } else {
        isTopLevelAccount = true;
return currAcctId;

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.