Apex Aide apexaide

display all open opportunities for all accounts in hierarchy

goravseth.com· ·Intermediate ·Admin ·2 min read
Summary

This solution shows how to build a Salesforce screen flow that retrieves all open opportunities across an entire account hierarchy. It addresses the challenge of finding related opportunities beyond a single account by navigating first to the top parent, then gathering all child account IDs recursively. Using collections and the IN operator in get elements enables efficient querying for all relevant opportunities. This approach helps Salesforce teams provide powerful visibility of related data in complex account hierarchies without heavy code.

Takeaways
  • Use a loop with get records and decision elements to navigate account hierarchies.
  • Collect all child account IDs into a collection variable including the ultimate parent.
  • Query opportunities using the IN operator against the collection of account IDs.
  • Display aggregated opportunity data in a screen flow data table for user visibility.
  • Avoid hitting governor limits by designing flows to handle large hierarchies cautiously.

A related list can highlight open opportunities on the account , for those people who find it too much work to look themselves to make it easy to see them. Recently a power user raised the need for finding open opportunities for other accounts within the hierarchy. So we built a screen flow to do this It was fairly straightforward, thanks to the relatively recent addition of the IN operator for get elements. It does require a get element in a loop, which is generally bad form but should be fine in this use case, as we are in a screen flow and you would need a 99 level deep hierarchy to hit the 100 query limit. There are probably other ways to solve this, but the key for me was to realize I must first navigate to the top of the hierarchy (via the get in the “loop”) and then work my way down, level by level, adding all the child account IDs to a collection variable.

Flow Builder