You need to sign in to do that
Don't have an account?
VRK
Unable to display related child contacts details for Account Parent Hierarchy in lighting Grid component
Hi am trying to display related contacts details for Account Hirearchy .
for example
Parent Accoun1 (Grand parent)
--> Test contact1 abc@gmail.com 122345566
--> Test contact2 abcd@gmail.com 5122345566
childParentAccount1 ( childParentAccount is child of Parent Account):
--> Test contact3 a1bc@gmail.com 6122345566
--> Test contact4 coc@gmail.com 1225645566
childChildParentAccount2 (childChildParentAccount2 is child of childParentAccount1 )
--> Test contact4 a1bc@gmail.com 6122345566
--> Test contact5 a1bc@gmail.com 6122345566.
I tried below code, but its can display only one Level .......but not display for leve2 , level 3 ...........
<aura:component controller="TreeGridExamples" implements="flexipage:availableForRecordHome,force:hasRecordId,force:lightningQuickActionWithoutHeader">
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<aura:attribute name="gridColumns" type="List" />
<aura:attribute name="gridData" type="Object" />
<aura:attribute name="gridExpandedRows" type="Object" />
<lightning:treeGrid columns="{! v.gridColumns }"
data="{! v.gridData }"
keyField="name"
aura:id="mytree"
hideCheckboxColumn="true"
/>
</aura:component>
controller :
({
doInit : function(component, event, helper) {
component.set('v.gridColumns', [
{label: 'name', fieldName: 'name', type: 'text'}
]);
helper.getData(component);
}
})
Helper :
({
getData : function (cmp) {
var action = cmp.get("c.getTreeGridData");
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
var data = response.getReturnValue();
var temojson = JSON.parse(JSON.stringify(data).split('items').join('_children'));
console.log(temojson);
cmp.set('v.gridData', JSON.parse(temojson));
}
// error handling when state is "INCOMPLETE" or "ERROR"
});
$A.enqueueAction(action);
}
})
Apex class:
public class TreeGridExamples {
@AuraEnabled
public static String getTreeGridData(String AccountId){
List<Account> accs = [Select Id , Name,(Select Id , Name,Title,Phone,Email from Contacts) from Account];
system.debug('accs1........'+accs);
Map<Id , Contact> opps =new Map<Id , Contact>( [Select Id , Name,(Select Id ,Name From Opportunities) from Contact]);
List<AccountWrapper> aooo = new List<AccountWrapper>();
for(Account a : accs){
AccountWrapper aWraper = new AccountWrapper() ;
aWraper.name =a.Name ;
aWraper.label =a.Name ;
List<Items> co = new List<Items>();
for(Contact c : a.Contacts){
Items conWrapp = new Items();
conWrapp.name =c.Name ;
conWrapp.label =c.Name ;
conWrapp.title =c.Title ;
conWrapp.phone =c.Phone ;
conWrapp.email =c.Email ;
co.add(conWrapp);
}
aWraper.items = co;
aooo.add(aWraper);
}
return JSON.serializePretty(aooo) ;
}
public Class AccountWrapper{
@AuraEnabled
public String name {get;set;}
@AuraEnabled
public String label {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 String title {get;set;}
@AuraEnabled
public String phone {get;set;}
@AuraEnabled
public String email {get;set;}
@AuraEnabled
public List<Items> items {get;set;}
}
}
Pls check and let me know whats wrong here in this code
Thanks
for example
Parent Accoun1 (Grand parent)
--> Test contact1 abc@gmail.com 122345566
--> Test contact2 abcd@gmail.com 5122345566
childParentAccount1 ( childParentAccount is child of Parent Account):
--> Test contact3 a1bc@gmail.com 6122345566
--> Test contact4 coc@gmail.com 1225645566
childChildParentAccount2 (childChildParentAccount2 is child of childParentAccount1 )
--> Test contact4 a1bc@gmail.com 6122345566
--> Test contact5 a1bc@gmail.com 6122345566.
I tried below code, but its can display only one Level .......but not display for leve2 , level 3 ...........
<aura:component controller="TreeGridExamples" implements="flexipage:availableForRecordHome,force:hasRecordId,force:lightningQuickActionWithoutHeader">
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<aura:attribute name="gridColumns" type="List" />
<aura:attribute name="gridData" type="Object" />
<aura:attribute name="gridExpandedRows" type="Object" />
<lightning:treeGrid columns="{! v.gridColumns }"
data="{! v.gridData }"
keyField="name"
aura:id="mytree"
hideCheckboxColumn="true"
/>
</aura:component>
controller :
({
doInit : function(component, event, helper) {
component.set('v.gridColumns', [
{label: 'name', fieldName: 'name', type: 'text'}
]);
helper.getData(component);
}
})
Helper :
({
getData : function (cmp) {
var action = cmp.get("c.getTreeGridData");
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
var data = response.getReturnValue();
var temojson = JSON.parse(JSON.stringify(data).split('items').join('_children'));
console.log(temojson);
cmp.set('v.gridData', JSON.parse(temojson));
}
// error handling when state is "INCOMPLETE" or "ERROR"
});
$A.enqueueAction(action);
}
})
Apex class:
public class TreeGridExamples {
@AuraEnabled
public static String getTreeGridData(String AccountId){
List<Account> accs = [Select Id , Name,(Select Id , Name,Title,Phone,Email from Contacts) from Account];
system.debug('accs1........'+accs);
Map<Id , Contact> opps =new Map<Id , Contact>( [Select Id , Name,(Select Id ,Name From Opportunities) from Contact]);
List<AccountWrapper> aooo = new List<AccountWrapper>();
for(Account a : accs){
AccountWrapper aWraper = new AccountWrapper() ;
aWraper.name =a.Name ;
aWraper.label =a.Name ;
List<Items> co = new List<Items>();
for(Contact c : a.Contacts){
Items conWrapp = new Items();
conWrapp.name =c.Name ;
conWrapp.label =c.Name ;
conWrapp.title =c.Title ;
conWrapp.phone =c.Phone ;
conWrapp.email =c.Email ;
co.add(conWrapp);
}
aWraper.items = co;
aooo.add(aWraper);
}
return JSON.serializePretty(aooo) ;
}
public Class AccountWrapper{
@AuraEnabled
public String name {get;set;}
@AuraEnabled
public String label {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 String title {get;set;}
@AuraEnabled
public String phone {get;set;}
@AuraEnabled
public String email {get;set;}
@AuraEnabled
public List<Items> items {get;set;}
}
}
Pls check and let me know whats wrong here in this code
Thanks
Refer the below link will help you to proceed further on your requirment.
https://www.sfdcstuff.com/2018/11/lightningtreegrid-displaying-account.html
Thanks!!