+ Start a Discussion
Arun MKArun MK 

How to identify the logged in user id, when the User has logged in as another User

Hi,

I have 2 users A and B. User A has Admin profile and so has the option to login as other users.

Now lets say, User A logged into the system and logged in as User B. 
Now, when I try to get the loggen in user Id using Userinfo.getUserId() or any other apex method, I get the User B record id. 

Is there a way, I can get the actual logged user i.e., User A record Id
SFDC_DevloperSFDC_Devloper
Hi Arun,

UserInfo.getUserId() - returns the current User Id

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.

go through the below links:

http://salesforce.stackexchange.com/questions/18108/how-to-get-the-current-user-profile-in-apex-class

https://developer.salesforce.com/forums/ForumsMain?id=906F0000000906dIAA

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_userinfo.htm

Thanks,
Rockzz
Arun MKArun MK
Hi Rockzz,

Thanks for your reply. 

If we try Userinfo.getUserId(), it just returns the User B record id. But what I want is the User A record id.

Regards,
MK
Cory CowgillCory Cowgill
I don't think you can access that information programatically via Apex.

The only location where this is available to my knowledge is in the Audit Log, which you can download as a CSV file, but can't get in Apex / Visualforce.

User-added image
umesh atryumesh atry
you can check profile by User.
Marco Sozzi 5Marco Sozzi 5
Hi,
did you find a solution for this problem? I have the same problem and want to know when a sysadmin log in as an another user. 

Thank you.
Marco.
Akshay DixitAkshay Dixit
Hi @Marco/ Arun,
Did you find a solution for this problem? 

Thanks 
Akshay
Manmohan SinghManmohan Singh
Hi Arun,
you an try below option to find this manually,

There is the Setup Audit Trail which tells you who logged in as another person.
Setup > Security Controls > View Setup Audit Trail

Thanks
Manmohan
pinnamanenipinnamaneni
Hi Arun,
Did you find any solution for this problem??

Thanks,
sandeep