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
Chris MairChris Mair 

Querying 4 levels for Lightning:TreeGrid

Hi All,

I'm trying to implement Lightning:TreeGrid with 4 levels of record hierarchy.  I've successfully implemented TreeGrid with two levels which is very simple to achieve with a single query.  However I'm not sure how to approach getting 4 levels GreatGrandParent, GrandParent, Parent, Child.  I have Master Detail on these objects using fields of the same api name with roll up summaries so if I can get the data to come back I think this will work really well to show totals and grand totals.

I know I probably need to use wrapper classes but I don't know how to get started as I'm more a declarative developer.

Thanks!

Chris
Raj VakatiRaj Vakati
You have to use the wrapper class like below 


Refer this links 

https://rajvakati.com/2018/05/10/usage-of-lightningtree/

https://rajvakati.com/2018/04/15/usage-of-lightningtreegrid/
​​​​​​​
public Class AccountWrapper{
        @AuraEnabled
        public String name {get;set;}
        @AuraEnabled
        public String label {get;set;}
        @AuraEnabled
        public Boolean expanded {get;set;}
        @AuraEnabled
        public List<Items> items {get;set;}
        
    }
    public Class Items{
        @AuraEnabled
        public String name {get;set;}
        @AuraEnabled
        public String label {get;set;}
        @AuraEnabled
        public Boolean expanded {get;set;}
        @AuraEnabled
        public List<Items> items {get;set;}
    }

 
Chris MairChris Mair
Hi Raj,

Your documentation is excellent.  I can't thank you enough for sharing this with the community.  I was able to get this working using your example, however the last level displays a chevron even though there is nothing to show.  Is it an issue with how I'm querying?  The code below works aside from that issue.  Thanks again for your response!

List<AccountWrapper> aooo = new List<AccountWrapper>();
        for(Revenue_Call_Great_Grandparent__c a : accs){
            AccountWrapper aWraper = new AccountWrapper() ; 
            aWraper.name =a.Name ;
            aWraper.label =a.Name ;

            List<Items> co = new List<Items>();
            for(Revenue_Call_Grandparent__c c : a.RevenueCallGrandparents__r){
                Items conWrapp = new Items();
                conWrapp.name =c.Name ;
                conWrapp.label =c.Name ;

                List<Items> wrapperOooo = new List<Items>();
                for(Revenue_Call_Parent__c o : opps.get(c.Id).RevenueCallParents__r){
                    Items ooo = new Items(); 
                    ooo.name = o.Name ;
                    ooo.label = o.Name ;
                    wrapperOooo.add(ooo);
                

                List<Items> wrapperFooo = new List<Items>();
                for(RevenueCallData__c o2 : opps2.get(o.Id).RevenueCallDatas__r){
                    Items ooo2 = new Items(); 
                    ooo2.name = o2.Name ;
                    ooo2.label = o2.Name ;
                    wrapperFooo.add(ooo2);
                }
                ooo.items =wrapperFooo ;
                //wrapperOooo.add(ooo);
                }
                conWrapp.items =wrapperOooo ;
                co.add(conWrapp);
            }
            aWraper.items = co;
            aooo.add(aWraper);
            
        }
 
Raj VakatiRaj Vakati
You can query the in different SOQL queries and  do the for loop 
Chris MairChris Mair
I'm not sure I understand but I also don't want to overstay my welcome because you helped so much.  Thanks again!

 
Teodora PopaTeodora Popa
I am also experiencing this same issue of the chevron displaying for child records at the lowest level of a lighting:treeGrid (aura) without any data. @Chris Mair, any luck getting rid of this issue?

@Raj Vakati, it appears your website may have gone down as a I am seeing "There has been a critical error on your website." when loading your links.