0

Trying to display related fields from junction object linked to 2 objects vis Master Detail :

@track columns = [{
    fieldName: 'related_field__r.Name',
    label: 'Name',
    type: "text",
    
  },
  { 
    fieldName: 'another_related_field__r.custom_field__c',
    label: 'My Custom Field',
    type: "text",
    
},
  { 
    fieldName: 'another_related_field__r.custom_field__c',
    label: 'My Custom Field',
    type: "text",
    
}
];

I have 3 test records and as we can see in the screenshot of the logs, the result from the Apex is non null and the code iterates through my 3 test records. We can see also on the web page that 3 rows are displayed in the datatable, one for each record. But the rows are empty. Me thinks it's about object relationship and field fetching. But not sure.

Datable Rows Created for each record

Logs show creation of 1 row per record

1
  • Will give it a try thx
    – user77098
    Commented Sep 4, 2021 at 22:02

1 Answer 1

3

The lightning-datatable will not be able to read child records or if you run a query from child to parent the parent fields (Any related field directly) In order to do this you have two options, you can either create a wrapper in Apex with all the fields that you want to display and pass it to LWC(which can be directly used by the datatable). OR you can pass the data to lwc and iterate over the payload in lwc, prepare a wrapper and pass it to your data table. Basically, data-table will not be able to read anything with a '.'(dot) operator. Hope it helps you. Do let me know if you have any more questions/concerns regarding this approach.

1
  • Thank you I will try that
    – user77098
    Commented Sep 4, 2021 at 19:44