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
Avinash Gadgil 3Avinash Gadgil 3 

I have following code to fetch the List of users in LWC using APex I am unable to fetch profile name from User. It is showing in console log but not showing in Lightning data table. How to show the same in Lightning data table in LWC

Apex Code: 
public with sharing class userListApexClassForLWC {
    @AuraEnabled(cacheable=true)
    public static List<User> userList() {
        return [Select Id, FirstName, LastName, Email, profile.Name, IsActive FROM  User Where IsActive=true LIMIT 5];
    }
}

LWC JS:

import { LightningElement, wire, track} from 'lwc';
import userListApexClassForLWC1 from '@salesforce/apex/userListApexClassForLWC.userList';
export default class UserListInLWC extends LightningElement {
  
    @track error;
    @track FirstName;
    @track LastName;
    @track Email;
    @track profile;
    @track IsActive;
    profileName;
   
    data=[]
    columns = []
   
     @track columns = [
        { label: 'First Name', fieldName: 'FirstName', type: 'text'  },
        { label: 'Last Name', fieldName: 'LastName', type: 'text' },
        { label: 'Email', fieldName: 'Email', type: 'email' },
        { label: 'Profile', fieldName: 'profileName', type: 'string' },
        { label: 'IsActive', fieldName: 'IsActive', type: 'boolean' },
    ];
    @wire(userListWrapper, {currentRecordId: '$recordId'})
    dataFn({data}){
        this.data = data;
    }
    @wire (userListApexClassForLWC1) wireduser ({error,data})
    {
        if (error) {
           this.error = error ;
        } else if (data) {
            this.data = data;
            profileName= data.profile.name;
            console.log(data);
        }
    }
}

LWC HTML:

<template>
    <lightning:card>
    <div style="height: 500px;">
        <template if:true={data}>
            <lightning-datatable
                     key-field="id"
                     data={data}
                     columns={columns}>
        </lightning-datatable>
        </template>
        </div>
    </lightning:card>
</template>
 
SwethaSwetha (Salesforce Developers) 
HI Avinash,
Does this similar post https://salesforce.stackexchange.com/questions/350198/lwc-data-shows-in-console-but-foreach-fails-to-display-it help? 
Thanks
Nikhil Shah 14Nikhil Shah 14
Hi Avinash,
Try updating your wire method like so - 

@wire (userListApexClassForLWC1) wireduser ({error,data})
    {
        if (error) {
           this.error = error ;
        } else if (data) {
           const dataList = [];
           data.forEach(record => {
           const dataRow = {};
           dataRow.FirstName = record.FirstName;
           dataRow.LastName = record.LastName;
           dataRow.Email = record.Email;
           dataRow.IsActive = record.IsActive;
           dataRow.profileName = record.profile.Name;
           dataList.push(dataRow);
           });
            this.data = dataList;
            console.log(data);
        }
    }