Get Current User Id Information in Lightning Web Components

Here in this post i am sharing how to get current user id information in different ways in salesforce…

VF Page:

Use {!$User.Id}

Lightning Component:

We have to call apex method to return system.UserInfo.getUserId() now we no longer have to do this method.

In the Lightning Controller, call

the $A.get(“$SObjectType.CurrentUser.Id”) to get the information like below..

var userId = $A.get(“$SObjectType.CurrentUser.Id”);


Ligtning Web Component:

import userId from ‘@salesforce/user/Id’;




<lightning-card title=”Get User Id” icon-name=”custom:custom14″>

User Id: {userId}


import { LightningElement } from ‘lwc’;
import strUserId from ‘@salesforce/user/Id’;

export default class GetUserId extends LightningElement {
userId = strUserId;

<?xml version=”1.0″ encoding=”UTF-8″?>
<LightningComponentBundle xmlns=”; fqn=”ShowUserDetail”>




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s