function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Bhavesh RekvarBhavesh Rekvar 

How to get Salesforce user using apex code

Hello,

I'm trying to how we can get the Salesforce user using apex code but did not getting any solution so please reach out.

ShirishaShirisha (Salesforce Developers) 
Hi Bhavesh,

Greetings!

You can either query the users by using the below SOQL query:
 
List<User> allUsers;

 allUsers = [SELECT Id, Name from User];

If you would like to get the current logged in user then you can use the below method.

UserInfo.getUserId() which returns the user id of the current user.

Please mark it as best answer if helps you to fix the issue.

Thank you!

Regards,

Shirisha Pathuri

Bhavesh RekvarBhavesh Rekvar

Hi Shirisha,

I'm totally new to salesforce development so could you provide the whole code to get salesforce users using apex code.

Please let me know where will see the output of the code and how can I use the value of the output in another function...