Get Current User Id in Salesforce

Author posted by Jitendra on Posted on under category Categories Salesforce and tagged as Tags , , with 1 Comment on Get Current User Id in Salesforce

How to get Current Logged in user Id in Apex, Visualforce, Lightning Component and Formula fields in Salesforce

Quick Code Snippets of how to get Current logged in user ids in Salesforce

Apex

System.debug('Current User Id - '+UserInfo.getUserId());

Visualforce

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

Aura Component

let currentUser = $A.get("$SObjectType.CurrentUser.Id");
Console.log(currentUser);

Lightning Web Components

Using wire

import USER_ID from '@salesforce/user/Id';
import NAME_FIELD from '@salesforce/schema/User.Name';
import EMAIL_FIELD from '@salesforce/schema/User.Email';

Formula Fields

$User.Id

Related posts

One thought on “Get Current User Id in Salesforce”

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.