How to fetch current user data in LWC

Telegram logo Join our Telegram Channel

In this post let us see how we can fetch user information from fields like UserName, Email, FirstName, LastName in Lightning web components. We will use standard import to fetch the User Id and the wired method to fetch other user fields.



import { LightningElement, wire } from 'lwc';
import { getRecord, getFieldValue } from 'lightning/uiRecordApi';

import USER_NAME from '@salesforce/schema/User.Username';
import FIRST_NAME from '@salesforce/schema/User.FirstName';
import LAST_NAME from '@salesforce/schema/User.LastName';

import USER_ID from '@salesforce/user/Id';
export default class UserInfo extends LightningElement {
    userId = USER_ID;
    @wire(getRecord, { recordId : "$userId", fields: [USER_NAME, FIRST_NAME, LAST_NAME]})

    get userName(){
        return getFieldValue(, USER_NAME);

    get firstName(){
        return getFieldValue(, FIRST_NAME);

    get lastName(){
        return getFieldValue(, LAST_NAME);


    <lightning-card variant="Narrow" title="User Info" icon-name="standard:user">
        <div class="slds-p-horizontal_small">User Id = {userId}</div>
        <div class="slds-p-horizontal_small">Username = {userName}</div>
        <div class="slds-p-horizontal_small">First Name = {firstName}</div>
        <div class="slds-p-horizontal_small">Last Name = {lastName}</div>


<?xml version="1.0"?>
<LightningComponentBundle xmlns="">
	<masterLabel>User Info</masterLabel>
	<description>User fetch info in LWC demo</description>

No comments :
Post a Comment

Hi there, comments on this site are moderated, you might need to wait until your comment is published. Spam and promotions will be deleted. Sorry for the inconvenience but we have moderated the comments for the safety of this website users. If you have any concern, or if you are not able to comment for some reason, email us at