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
eliotstock2eliotstock2 

accessing the user object within a custom controller or standard controller extension

Hi there.

 

Is there any way to get access to the User object from within a custom controller or an extension to a standard controller? It seems strange that I have it in the VF page but not in the controller.

 

Thanks,

 

Eliot Stock.

Best Answer chosen by Admin (Salesforce Developers) 
aalbertaalbert

Yes, you can access the User object in Apex (ie controller). You could use the UserInfo methods or query the User object for a specific dataset:

 

 

//just an example List<User> users = [select id, username from User LIMIT 10];

 

 

 

All Answers

aalbertaalbert

Yes, you can access the User object in Apex (ie controller). You could use the UserInfo methods or query the User object for a specific dataset:

 

 

//just an example List<User> users = [select id, username from User LIMIT 10];

 

 

 

This was selected as the best answer
MyGodItsColdMyGodItsCold

And to get the user of the page -

 

public User me = [SELECT ID, Name FROM User WHERE ID = :userInfo.getUserId()];

eliotstock2eliotstock2
Thanks both of you. Wasn't aware of the UserInfo object. It's not in the obvious place in the docs.