Below, you can find how to get the Id of the user currently logged on Salesforce in Apex class, Visualforce pages, Lightning Components, and Formula fields:

APEX

Visualforce

Aura

                    

 

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

Lightning Web Components (LWC)

                    

 

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

Formula Field

                    

 

$User.Id 
// OR
CASESAFEID($User.Id)