You need to sign in to do that
Don't have an account?
Paridhi Bindal 9
Display Account Name instead of ID in LWC Datatable
Hello, I am displaying custom object records in Datatable via @wire, Since account is a lookup, it displays account id instead of account name. How can I display the name of the account in the colum.
I have tried the following but it doesn't work. Please suggest.
{
label: 'My Accounts',
fieldName:'My_Account__r.Name
type: 'text',
sortable: true
}
I have tried the following but it doesn't work. Please suggest.
{
label: 'My Accounts',
fieldName:'My_Account__r.Name
type: 'text',
sortable: true
}
You can't traverse the parent details directly in datatable using dot operator. As an alternate we can use the below way:
Change the wire a property in wire a function for fetching the data to datatable. Then overide the data using JS.
Solution 1:
https://www.srinivas4sfdc.com/2019/11/how-to-access-parent-object-or.html
Solutions 2: https://salesforce.stackexchange.com/questions/293088/lwc-salesforce-get-parent-in-datatable-column
https://salesforce.stackexchange.com/questions/287262/flatten-data-to-display-it-using-lightning-datatable-in-lwc
https://salesforce.stackexchange.com/questions/290393/lwc-relationship-fields-in-data-table-flattening-in-wire
Thanks,
Maharajan.C
All Answers
You can't traverse the parent details directly in datatable using dot operator. As an alternate we can use the below way:
Change the wire a property in wire a function for fetching the data to datatable. Then overide the data using JS.
Solution 1:
https://www.srinivas4sfdc.com/2019/11/how-to-access-parent-object-or.html
Solutions 2: https://salesforce.stackexchange.com/questions/293088/lwc-salesforce-get-parent-in-datatable-column
https://salesforce.stackexchange.com/questions/287262/flatten-data-to-display-it-using-lightning-datatable-in-lwc
https://salesforce.stackexchange.com/questions/290393/lwc-relationship-fields-in-data-table-flattening-in-wire
Thanks,
Maharajan.C
get reference following dummy lwc.
we are expacting that account is like a parent.
Let me know if it helps you and marking it as best.
Thank You
you can take look for the below link example for your solution
HTML:
JAVASCRIPT CONTROLLER
Apex class: For Refrence :
https://www.salesforcecodecrack.com/2019/10/display-reference-data-in-lwc.html
If you find your solution than please mark as best answer
Thanks and Regards,
Suraj Tripathi
To avoid that exception please follow the below steps:
1. In SOQL query add that lookup field api name to check the lookup has value or not from JS : (for exam: my Lookup field API Name is : My_Account__c )
2. Update the JS like below.
Thanks,
Maharajan.C
Thank you.
Hi Abhilash,
Just have an if condition to check if My_Account__c is not undefined and then make the assignment
Something like this
I assume that your issue has been resolved. Additionally, I have a suggestion for you. Make sure to check out the article at https://logcodes.com/lwc-datatable-in-salesforce/. It provides a comprehensive guide on how to use the Lightning Data Table in Salesforce. This guide covers handling row selection actions, implementing sorting, and enabling pagination functionality. It's a valuable resource to enhance your Salesforce development skills!