function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ravi Kumar 6740Ravi Kumar 6740 

How to use lastmodifiedby Name in lightning datatable using LastModifiedById?

Yogendra JangidYogendra Jangid
Hi Ravi,

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.
Ravi Kumar 6740Ravi Kumar 6740
I have used same in SOQL but i am not getting username in Datatable, instead I am getting Id's of user
Yogendra JangidYogendra Jangid
Hi Ravi,

Can you put here the code snippet how are you showing the value in datatable if possible
Suraj Tripathi 47Suraj Tripathi 47
Hi Ravi,
Greetings!

If you want to use the parent record information in the child record object.
Please use ParentObjectAPIName.FieldAPIName

like
SELECT LastModifiedBy.Username FROM Account;
In Datatable,
Use key.LastModifiedBy.Username

If you find your Solution then mark this as the best answer. 

Thank you!

Regards,
Suraj Tripathi
Ravi Kumar 6740Ravi Kumar 6740
Hi Suraj,

it is not working,
User-added image

Thanks,
Ravi
Suraj Tripathi 47Suraj Tripathi 47
Hi 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
Teja AmereTeja Amere
You can able to retrieve last modified by name and last modified date and display in custom LWC datatable. Here's how : -
To display lastmodifiedbyname in custom LWC
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.