Get Current User Id in Salesforce

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


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


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

Aura Component

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

Lightning Web Components (LWC)

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


Related Posts


7 responses to “Get Current User Id in Salesforce”

  1. appybix Avatar

    Hi Jitendra thanks for sharing this code which is very significant to the developers.

  2. Paul R Avatar
    Paul R

    Very useful info. Thanks.

    For Formula fields in a Lightning Flow Builder formula, use CASESAFEID($User.Id) if you are comparing to id values returned by the GetRecords Element. $User.ID on it’s own returns a 15 character id, not the newer 18 character id.

  3. kasim Avatar

    Hello Jitendra,
    Can you please post how get logged in user profile name without apex call in either LWC or Aura

    1. Ashima Avatar

      Hi Kasim,

      Could you please confirm if you were able to get user profile name without apex class?

  4. m7yank Avatar

    where I should write this code to get user id

  5. Julian Avatar

    What would be the syntax in Workbench?

  6. DIANA Avatar

    onde devo escrever este código para obter o ID do usuário com APEX?

Leave a Reply

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

Discover more from Jitendra Zaa

Subscribe now to keep reading and get access to the full archive.

Continue Reading