Welcome to SFDC Share Point

Salesforce Blogs

Current User Id in Salesforce

While working on salesforce we come across the need of fetching user id. Here is the way to get user id in Apex, Lightning Component, LWC and Formula Field.

Formula Field $User.Id

Apex UserInfo.getUserId())

Lightning Component var currentUserId = $A.get("$SObjectType.CurrentUser.Id"); Console.log(currentUserId);


  <h1>Visualforce Page</h1> 
   <p>UserId: {!$User.Id}</p>
   <p>User Email: {!$User.Email}</p>

Lightning Web Component

import USER_ID from '@salesforce/user/Id';
import USER_NAME_FIELD from '@salesforce/schema/User.Name';
import USER_EMAIL_FIELD from '@salesforce/schema/User.Email';

For more posts and short tricks follow the Facebook page here. https://www.facebook.com/sfdcsharepoint