You need to sign in to do that
Don't have an account?
Jenna Hildebrand
Apex to Count Total Employees in Account Hierarchy
Hello,
I need to write an apex class that sums the Employees field on all accounts within a hierarchy and updates a custom field called "Total Hierarchy Employees" with the result on each account. For example:
I've gotten my apex class started, but I'm having trouble avoiding nesting loops and such. Any help is greatly appreciated.
Thank you!
I need to write an apex class that sums the Employees field on all accounts within a hierarchy and updates a custom field called "Total Hierarchy Employees" with the result on each account. For example:
- Test Account 1 – 10 employees
- Test Account 2 – 15 employees
- Test Account 3 – 12 employees
I've gotten my apex class started, but I'm having trouble avoiding nesting loops and such. Any help is greatly appreciated.
Thank you!
One important item to note—I'm not using the standard Parent Account field because I need the logic to be able to handle multiple tiers as well as include accounts that do not have a parent (for example, accounts that are not part of a hierarchy are their own Ultimate Parent Accounts). Also, I can't use AggregateResults because the field I'd be grouping by is a formula field.
Appreciate any assistance here!