You can able to retrieve last modified by name and last modified date and display in custom LWC datatable. Here's how : -
You can able to use LastModfiedBy.Name, in the query.
SELECT Name, Industry, LastModifiedBy.Name and LastModifiedDate FROM Account;
But that's not all. While defining datatable columns in JS, You need to create a column with custom fieldName like below code- Note - Don't give type attribute. It may cause malfunction to display values.
const COLUMNS =[
{label:'Account Name',fieldName:'Name',type:'text'},
{label:'LastModifiedBy',fieldName:'lastModifiedBy'},
{label:'CreatedBy',fieldName:'createdBy'},
]
export default class Task extends LightningElement {
tableData;
columns=COLUMNS;
//to get the data from the apex use @wire property
@wire(getData)
dataHandler({data}){
console.log(data);
if(data){
return this.tableData= data.map((ele) => ({
...ele,
...{'lastModifiedBy':ele.LastModifiedBy.Name}
}))
}
Here lastModifiedBy is a reference field and by using above code, you can able to display last modified by name. Please mark it as best answer if it helps you.
Have LastModifiedBy.Name in your SOQL and use that field reference in your lightning datatable.
Hope this answers your question, if so please can you mark this as best answer.
Can you put here the code snippet how are you showing the value in datatable if possible
Greetings!
If you want to use the parent record information in the child record object.
Please use ParentObjectAPIName.FieldAPIName
like In Datatable,
Use key.LastModifiedBy.Username
If you find your Solution then mark this as the best answer.
Thank you!
Regards,
Suraj Tripathi
it is not working,
Thanks,
Ravi
Please avoid using key, I don't understand the purpose of using key in the code.
or please provide some more details
If you find your Solution then mark this as the best answer.
Thank you!
Regards,
Suraj Tripathi
You can able to use LastModfiedBy.Name, in the query. But that's not all. While defining datatable columns in JS, You need to create a column with custom fieldName like below code-
Note - Don't give type attribute. It may cause malfunction to display values.
Here lastModifiedBy is a reference field and by using above code, you can able to display last modified by name.
Please mark it as best answer if it helps you.