Activity › Forums › Salesforce® Discussions › How to get the userId of currently logged user in salesforce?
-
How to get the userId of currently logged user in salesforce?
Posted by kapil on March 20, 2018 at 2:04 PMHow to get the userId of currently logged user in Salesforce?
Parul replied 7 years, 8 months ago 5 Members · 4 Replies -
4 Replies
-
Hi Kapil,
You can get the ID’s of all the currently logged in users by using this global function: UserInfo.getUserId().
Thanks
- [adinserter block='9']
-
Hi Kapil,
For apex Class, you may use and UserInfo.getUserId(), and for a Visualfroce page, you may use {!$User.Id}.
Hope it helps 🙂
-
Hi,
You can use userinfo class in apex to obtain the information related to logged in user.
You can get Id using userinfo.getUserId() and if userinfo class is not able to provide info use query to query those fields .
On VF you will need to use
<apex:outputText value=”{!$User.Id}”>
You are using outputfield and hence you are not able to save the codeEdit::
A sample getter setter User object type variable will be handy
public class MailExtension{
public user currentuser{get;set;}
public MailExtension(ApexPages.StandardController cont){
opp =(Opportunity) cont.getRecord();
currentuser=new User();
currentuser=[Select Id,Name,Email from User where Id=:userinfo.getuserId()];
}
}
A sample VF tag or mark up will be as follows<apex:outputfield value=”{!currentuser.Id}”/>
<apex:outputfield value=”{!currentuser.Email}”/>Hope this helps you.
-
Hi Kapil,
There is different way to get the userId -:
In apex -: Use UserInfo.getUserId()
In VisualForcePage -: Use {!$User.Id}
Thanks
Log In to reply.