Skip to main content
New tool CRON Expression Builder — preview next run times before you schedule Apex. Open the builder →
A screenshot showing Apex code examples for getting the current logged in user ID in Salesforce.
Apex

Get logged in user id in Salesforce

As far as you progress with configuration or customization with Salesforce, you require to write some complex logic. Performing the logic based upon currently logged in user is also very much required in each business scenario. Here I have gathered ways to get logged in user ids in Formula, Visualforce page, Lightning Component, Apex, Lightning Web Components.

Formulas, Validation Rules, Workflows, Approval Processes

$User.Id

Apex

Id UserId = UserInfo.getUserId();

Visualforce

UserId: {!$User.Id}

Lightning Component

User variable is not directly available on lightning component as of now, this we need to get from lightning component controller.

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

Lightning Web Components (LWC)

import USER_ID from '@salesforce/user/Id';
Newsletter

One email every Tuesday

New guides, tool updates, and the release-note changes that break things.

No spam. Unsubscribe in one click.

Comments

Loading comments...

Leave a Comment