+1 vote
1 view
in Salesforce by (11.3k points)

I would like to know if there is a way to find out in APEX when an particular user is logged in directly or via the "Login As" feature from the organization's user list. The UserInfo class doesn't seem to provide any methods for this purpose and i need to know this in my apex code.

thanks in advance

1 Answer

+1 vote
by (28.6k points)

I assume this would be cookie-based. 

If this is the case, you could try and confine it by tracking the cookie changes when you log in as another user. If you can find it then you can check for the presence of this cookie in Apex using

Cookie counter = ApexPages.currentPage().getCookies().get('loginAsCookieHere');
...