How to get current User Id using Apex in Salesforce?

UserInfo.getUserId() - returns the current User Id

Sample Code:

User Usr = new User();


Usr = [SELECT Phone, Id FROM User WHERE Id = : UserInfo.getUserId()];

the above code will return the current user's Phone and Id who execute this code.

Cheers!!!

1 comment: