Agenda
This blog gives us a brief that how we can get details of the Logged-in user in the Lightning Web Component.
What we are going to do.
In this blog, we will fetch the current user id by importing the “@salesforce/user/Id”, then we use the imperative way to fetch user’s details with the help of ID from the apex method.
Lightning Web Component
Lightning Web Components is lightweight and delivers exceptional performance. Most of the code you write is standard JavaScript and HTML.
To fetch the current user’s details first we need to fetch the Id of the logged-in user and to do that we’ll use the standard way provided by Lightning Web Component.
import USER_ID from '@salesforce/user/Id';
Apex Class:
Then, we use this Id to get the users details from the database and provide it to the associated component.
JavaScript Syntax:
So, by using the USER_ID property we will get the Current Logged in user, and we will be using this property further to fetch the details with the help of Apex, we can fetch any information about the current user and display them in LWC.
And we are expecting the output as:
HTML Syntax:
And after getting the details, the final touch is to display it over the component. So, it can be visible in the org and users of the org can see and use it.
And the resulted outcome is:
Blog’s conclusion:
This blog gives us a brief that how we can get details of the Logged-in user in the Lightning Web Component. And we can fetch any information about the current user and display them in LWC.




Hi bro, again you explained the concept in a simple manner. Please keep posting blogs like this and help us to learn new things. I am always very happy reading ur blogs and appreciate your work.
ReplyDelete