html code

Retrieve the Current User’s ID in Salesforce

Swift Code Snippets Demonstrating How to Retrieve IDs of Currently Logged-In Users 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