You need to sign in to do that
Don't have an account?

Sample Code to Traverse Hierarchy?
I am diving into my first Apex trigger creation, and I'm hoping someone out there has some sample code that I can drop in. We rely heavily on account hierarchies, and I'm writing some triggers to automatically update a few fields across the entire hierarchy when a user changes a value on one account in a family. The starting point of this trigger is therefore being able to traverse the entire account family, and get a Set of IDs to update that represent all the accounts in that account family. Our hierarchies can be fairly deep -- sometimes as many as 3 or 4 levels, and I'd like the code to be able to work from anywhere in the hierarchy and update ALL related accounts.
Does anyone have a sample that would take a single account ID as its input and return a set of IDs for all accounts in the family? It would be a huge time saver.
I'll be sure to post my finished trigger for all to use when it's done!
Thanks in advance.
Does anyone have a sample that would take a single account ID as its input and return a set of IDs for all accounts in the family? It would be a huge time saver.
I'll be sure to post my finished trigger for all to use when it's done!
Thanks in advance.
Hello Jay,
I dont have a drop-in example but this Salesforce Labs applicatino contains a Visualforce controller that traverses large account hierarchies in an execution limit friendly way. This may get you going in the right direction.
http://www.salesforce.com/appexchange/detail_overview.jsp?id=a0330000006m4OYAAY Inline Account Hierarchy
All Answers
Hello Jay,
I dont have a drop-in example but this Salesforce Labs applicatino contains a Visualforce controller that traverses large account hierarchies in an execution limit friendly way. This may get you going in the right direction.
http://www.salesforce.com/appexchange/detail_overview.jsp?id=a0330000006m4OYAAY Inline Account Hierarchy
No problem, I hope it's very usefull to you.
-Matt
Do you have any idea on how far this would scale?
I'm looking at 1000 accounts and possibly up to 30000 in the hierarchy and possibly 3-4 levels deep.
At what point would I start to hit the governor limits? Note this would only be used in a calculation and I wouldn't be displaying all the accounts at once.
Thanks.