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
Mike @ BlackTabMike @ BlackTab 

Access $User.Email From Apex Controller

Hello,

 

I'm trying to access the $User.email global variable from within an Apex class. Is this possible? I just need to get the running user's email address.

 

A quick response will be very helpful,

Thanks

Navatar_DbSupNavatar_DbSup

Hi,


I don’t think that you can use global variable inside the controller. So you have to make the query on User to get the email id of that user or you can pass the value of email using global variable inside the controller by using apex:param tag from vf page.

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

DoomsdayDoomsday

Hi,

You can use this, eg:
UserInfo.getUserName();

Or query like this: [SELECT Email FROM User WHERE Id=:UserInfo.getUserId()];