function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
jayhunterjayhunter 

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.
Best Answer chosen by Admin (Salesforce Developers) 
mfriendmfriend

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 


 

 

Message Edited by mfriend on 01-28-2009 08:50 AM

All Answers

mfriendmfriend

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 


 

 

Message Edited by mfriend on 01-28-2009 08:50 AM
This was selected as the best answer
jayhunterjayhunter
Thanks for pointing me to that!  Besides being a good starting point, it's a nifty little add-in that my users will appreciate. 
mfriendmfriend

No problem, I hope it's very usefull to you.

 

-Matt

voutchervoutcher

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.