Watch a DEMO here…..


Step 1:

Download the Jquery Plugin from here. Upload this Zip file into Static Resources with the name “Jtreeview”

Step 2:

Create the Apex Class “treenodes” and paste the below code.

  public class treenodes {    /* Wrapper class to contain the nodes and their children */  public class cNodes  {     public List parent {get; set;}   Public Account gparent {get;set;}     public cNodes(Account  gp, List p)   {       parent = p;       gparent = gp;   }  }  /* end of Wrapper class */     Public List hierarchy;    Public List getmainnodes()  {      hierarchy = new List();      List tempparent = [Select Id,Name from Account];      for (Integer i =0; i< tempparent.size() ; i++)      {          List tempchildren = [Select Id,FirstName,LastName,(Select Id,CaseNumber,Subject from Cases) from Contact where AccountId = :tempparent[i].Id];          hierarchy.add(new cNodes(tempparent[i],tempchildren));       }         return hierarchy;  }     }

Step 3:

Create a Visualforce Page “TreeViewDemo” and paste the below code.


  • parent.gparent.Name}"/>             
      • ||  

Note: You may modify the hierarchy by replacing the Objects and the queries with your required ones. Also, you may have to optimize the apex class to handle more than 100 queries as this demo has a SOQL query within a FOR loop (An Example of bad programming practice).

Written by 

I am Sakthivel Madesh, a certified Salesforce Advanced Developer & Administrator working on Salesforce Technology since 2011. I am currently working in Techforce Services as Sr. Salesforce Developer. I have worked on multiple technologies Like PHP, Java, Salesforce, I am very passionate about Salesforce and to earn 15x Salesforce Certification. I love Trailhead for learning Salesforce Skill and Become a Trailhead 5x Ranger too. I Love to Learn & Share my Salesforce knowledge to Salesforce Learners/Beginner using My Blog and Salesforce Community.

Leave a Reply

Your email address will not be published. Required fields are marked *