A Salesforce account hierarchy is built from the Parent Account field, and SOQL can climb at most five levels per relationship path in dot notation. Grouping opportunities by ParentId rolls up only one level and splits top-level accounts into a null group. A correct rollup resolves every account to its root first, then sums opportunities once per root. Decide whether history uses today’s hierarchy or the one in force at the time, since a reparented account changes prior-period totals.
The one-line rollup is wrong
A request for revenue by customer usually becomes a GROUP BY. The first attempt groups won opportunities by Account.ParentId, and the result looks like a list of parent companies. Three things have gone wrong, none of them with an error.
First, the grouping only climbs a single level. In a fictional group with a holding company, two regional companies and six branches, branch deals roll into the regional companies and stop there. Second, deals booked directly on the holding company have a null parent on their account, so they land in a blank row and never reach the group. Third, every standalone account without a parent falls into that same blank row, which then looks like your largest customer.
Most teams treat this as an aggregation problem and get it backwards. You walk the graph first and aggregate after.
SELECT Account.ParentId, SUM(Amount) won
FROM Opportunity
WHERE IsWon = true
AND CloseDate >= 2026-01-01 AND CloseDate <= 2026-09-30
GROUP BY Account.ParentId
-- One level only. A null group holds both top-level
-- parents and every standalone account.Resolve each account to its root
Salesforce’s documented limit is five levels within a child-to-parent relationship, with up to 55 such relationships in one query. That lets you read four ancestors of every account in a single pass. A highest ParentId that’s still populated means the chain continues beyond what the query could see, so run the same query again starting from those accounts until nothing remains.
The newer support for five levels of parent-to-child subqueries, available from API version 58.0, goes the other way and helps when you start at a known group and want its descendants. For a full customer rollup I’d stay with the child-to-parent walk, because it visits each account once.
Store the output as a two-column map of account ID to root account ID, and include a root that points to itself, so top-level accounts resolve like any others. As far as the sources I checked show, the standard hierarchy gives you parent links and no standard field holding the ultimate parent, and at least one Salesforce industry package adds its own root account field for this reason. An earlier admin or a managed package may already have built one, so run describeSObjects on your org. Salesforce calls that the most reliable way to identify relationships.
SELECT Id, ParentId,
Parent.ParentId,
Parent.Parent.ParentId,
Parent.Parent.Parent.ParentId,
Parent.Parent.Parent.Parent.ParentId
FROM Account
-- For each row, the root is the last non-null ID on the chain.
-- If the deepest ParentId is populated, repeat from that ID.
-- Guard against a loop: stop if an ID appears twice on one path.
SELECT AccountId, SUM(Amount) won
FROM Opportunity
WHERE IsWon = true
AND CloseDate >= 2026-01-01 AND CloseDate <= 2026-09-30
GROUP BY AccountId
-- Join the two results on the root map, then sum per root.Permissions change the shape of the tree
Run the walk as an integration user with broad access and you have one hierarchy. Run it as a sales manager and you may have another. Salesforce notes that the hierarchy view does not show details of accounts a person lacks permission to view, and a query made as that person may not resolve a parent they cannot read. Their rollup can then stop part way up and report a branch as if it were a root.
Don’t paper over this by pre-computing a root map under a powerful account and exposing it to everyone, because a root name can itself disclose a relationship the sharing model hides. A group-level view for sellers is a decision for the people who own your sharing model. They should make it as a policy and test it with a low-privilege user.
The native viewer makes a poor reference for large groups. The Account Hierarchy page displays up to 2,000 accounts in Lightning Experience and 500 child accounts in Classic. Anyone checking a very large rollup by eye in that view may be comparing it with an incomplete picture.
Today’s parent or the parent at the time
Suppose a fictional group acquires a company in June and an admin sets the Parent Account field. With a current hierarchy, the group’s revenue for January through May rises overnight in every report, and no opportunity has changed. For a retention or growth calculation, you’ve just mixed real expansion with an acquisition.
Both views have a use. Account planning usually wants today’s structure, since it asks who the customer is now. Growth reporting usually wants the structure effective at the time, or an explicit restatement with an acquisitions line. Only the second needs extra work, and you have to start before you need it: keep a dated copy of the root map, and consider tracking changes to Parent Account if the field is available for history tracking in your org. Field history can only begin when tracking is turned on and retention limits apply, so I’d lean on a monthly copy of the map.
Write the choice into the metric definition and print it on the output. Current hierarchy as of October 31 is short enough to fit in a chart subtitle.
Checks that find the bad data
Hierarchies decay. Import jobs need the parent to exist before the child, and Salesforce’s import guide calls that out, so a failed load tends to leave orphans. A few queries and comparisons will show what state yours is in.
- Depth distributionCount accounts per level. A long tail of very deep chains usually means someone used the hierarchy for something other than corporate structure.
- Mixed meaningsCheck whether parents represent legal ownership, buying groups, resellers or territory groupings. Using one field for several ideas makes every rollup wrong for somebody.
- Cross-region childrenA subsidiary owned by a different region creates a choice: does its revenue stay with the region or follow the parent? Find these first, because they will be the first ones challenged.
- Reconciliation to financeA CRM parent is rarely the same as a billing entity. When comparing to an ERP, use a maintained identifier mapping and report the unmatched amount. Similar names give a steward a lead. They’re too weak to serve as a join.
- LoopsYour walk needs a guard against a chain that returns to itself. Report a detected loop as a data defect, so the job neither runs forever nor drops the account without saying so.
Three accounts to bring to any analytics tool
Prepare three accounts with known answers: a standalone, a parent with subsidiaries at more than two levels, and one child whose owner differs from the parent’s region. Ask for revenue by customer, then ask for the same figure as a person who cannot see part of the group. I’d want the answer to name the level it reported at and what it could not see.
With us, a Salesforce question runs under the asker’s sign-in, so sharing rules, field-level security and the role hierarchy decide what comes back, and two people can correctly get different numbers. The answer shows Answered as and Why you can see this, along with the SOQL and what was not included. A word like customer, with meanings that give different results, gets one question listing them. Pick your level on purpose there.
Bring three business questions
Explore your sources, definitions, and review criteria with our team. Please keep credentials and sensitive records out of the inquiry.