feat: add sobject hierarchy #389
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This utility function was created for the following reason. Our team kept writing code snippets that looked like the following:
There were many places where people would query five lookup levels deep in order to get some information from a hierarchy. However, not only does this lead to awkward looking code as above, but it also does not handle the case where there are more than five levels of the hierarchy, leading to bugs.
This new functionality would handle the above case in the following manner:
The utility function getUntilTopOfHierarchy returns a map of ids that were input into the function, with a list of sobjects that represent their hierarchy, from bottom to top. This will parse out the entire hierarchy, starting from the given record. It may use multiple SOQL statements to reach the top. More specifically, for every five levels of hierarchy, there must be one SOQL performed (since that is the salesforce max).
Thus, if you want to get the top of the hierarchy of the account, one only needs to get the last element of the list associated to the input id.
We believe that this greatly simplifies navigating hierarchies (which is something that our team kept doing again and again) and believe that this could be helpful functionality for other teams out there.
This change is