Home Visual Force Tree View in a Visualforce Page… Accounts/Contacts/Cases in a single view
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).

You may also like

Leave a Comment