0

I have been working on a lightning:treeGrid for the last while. Although the data is definitely getting through to the browser (I can see the child array in the console), I cannot get the tree to expand and show the child data.

I am having to use a wrapper class, because the child record is a case, whereas the parent record is a custom object, and although they are related to each other they share no fields.

Does anybody know if this can work? Or does the relationship between objects need to be a clear parent-child relationship?

screenshot of console

5
  • can you show the JSON string you are getting in browser? – salesforce-sas Jul 22 '19 at 13:58
  • Array(2) 0: IncidentDate: "2019-07-04T00:00:00.000Z" Name: "Incident - 000412" PostalCode: "NW10 7NZ" incidentId: "a060Q000003iBfXQAU" _children: Array(1) 0: CaseNumber: "00001548" Name: "00001548" Status: "Created" caseId: "5000Q000003k6T2QAI" incidentId: "a060Q000003iBfXQAU" – danmwendo Jul 22 '19 at 14:12
  • Sorry, not sure how to format this properly. – danmwendo Jul 22 '19 at 14:14
  • you can do console.log(JSON.stringify(response.getReturnValue())); Then you can copy from browser log – salesforce-sas Jul 22 '19 at 14:22
  • hi salesforcesas, I have attached a screenshot of the console to my original post. – danmwendo Jul 22 '19 at 16:22
0

It appears your _children records have different fields compared to parent record. treeGrid is for displaying self relationship (like to parent to child accounts).

However, you can have properties in wrapper class to have both parent and child fields.

public class wrapper {
    @AuraEnabled ParentName;
    @AuraEnabled ParentPostalCode;
    @AuraEnabled ParentIncidentId;
    @AuraEnabled ParentIncidentDate;
    @AuraEnabled ChildCaseNumber;
    @AuraEnabled ChildStatus;
    @AuraEnabled ChildCaseId;
}

Using this treeGrid will work. But in parent record, child fields will be blank and in child records, parent fields will be blank. These fields should reflect in both parent record and _children array of objects to work properly.

2
  • Hey salesforcesas! Thanks for the info. It is what i feared. Do you think achieving my aims would be possible using LWC instead of plain aura based components? – danmwendo Jul 22 '19 at 18:00
  • Almost all aura components load LWC components behind the scenes. But there are some differences due to 2 way binding nature and one way binding nature. tree-grid is same in both. For ref: developer.salesforce.com/docs/component-library/documentation/…. You need to build all custom components for achieving parent child records without common fields – salesforce-sas Jul 22 '19 at 18:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.