Get any field of current logged in User in LWC

 Get Current User Details in LWC

In my last post you can see how to get current logged in user Id, sometimes we need some other fields too. here we can learn how to get any field of current logged in user without calling apex class. 

1. First we need to get the current logged in user id.
[import Id from '@salesforce/user/Id';]

2. Using this current logged in user Id we can call the getRecord method of uiRecordApi to get any field value of that user.
If you don't' know how to use getRecord check it out my previous post of Update any record without using apex class in LWC.
[import { getRecord } from 'lightning/uiRecordApi';]

Now let's check with an example component.

    <lightning-card title="Get Current User Details" icon-name="standard:user">
        <div class="slds-m-around_medium">
            <p>User Id: {userId} </p>
            <p>User Name: {name} </p>
            <p>User Email: {email} </p>

[import { LightningElement , wire} from 'lwc';
import Id from '@salesforce/user/Id';
import { getRecord } from 'lightning/uiRecordApi';
import NAME_FIELD from '@salesforce/schema/User.Name';
import EMAIL_FIELD from '@salesforce/schema/User.Email';

export default class GetCurrentUserDetails extends LightningElement {
    userId = Id;

    @wire(getRecord, { recordId: Id, fields: [NAME_FIELD, EMAIL_FIELD]}) 
    userDetails({error, data}) {
        if (data) {
   = data.fields.Name.value;
   = data.fields.Email.value;
        } else if (error) {
            this.error = error ;

[<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="">

You can also find the above code in SWDC WORLD repo.



Android Apps,1,Apex,7,Apex Methods,1,Batch Apex,2,Chrome Add-on,1,Chrome browser,1,Coding Best Practices,2,CRM Basics,1,cURL,1,Database Query,1,Dataset,1,Dynamic Apex,3,Dynamic SOQL,1,Einstein Analytics,9,Future Apex,1,Git,1,Google Chrome,1,IDs and Urls Hacks,1,JS for LWC,5,Lightning Components,2,lightning Page,1,Lightning Web Components,14,Linux for Windows users,1,LWC,16,LWC-JEST,7,Queueable Apex,1,Redirect page,1,REGEX,1,REST API,1,Salesforce CRM,1,Salesforce Errors,1,Salesforce Handy Commands,1,Salesforce Interview Questions,14,Salesforce Lightning,1,Salesforce New Features,1,Salesforce Tasks,2,Schedule Apex,1,SLDS,4,SVG Image,3,Test Class,1,Triggers,1,uiObjectInfoApi,1,Visualforce Pages,3,Visualforce Pagination,2,VS Code,2,Wave Analytics,7,Winter Release Notes,1,workbench,1,
SWDC WORLD (Software Development Center Of The World) - is a Multi author and Multi Technology Blog: Get any field of current logged in User in LWC
Get any field of current logged in User in LWC
Get any field of current logged in User in LWC,Get Current User Details in LWC, Using Wire Service get current user details, get any user details lwc
SWDC WORLD (Software Development Center Of The World) - is a Multi author and Multi Technology Blog
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy