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.
n
Formula Fieldn
$User.Id
n
Apexn
UserInfo.getUserId())
n
Lightning Component n
var currentUserId = $A.get("$SObjectType.CurrentUser.Id");nConsole.log(currentUserId);
n
Visualforce
n Visualforce Page
n UserId: {!$User.Id}
n User Email: {!$User.Email}
n n
Lightning Web Component
import USER_ID from '@salesforce/user/Id';nimport USER_NAME_FIELD from '@salesforce/schema/User.Name';nimport USER_EMAIL_FIELD from '@salesforce/schema/User.Email';n
For more posts and short tricks follow the Facebook page here. nhttps://www.facebook.com/sfdcsharepoint