Salesforce UserInfo session type in APEX

1.1k views Asked by At

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

2

There are 2 answers

0
Samuel DR On

As far as I know this isn't possible with salesforce.

0
Daniel Ballinger On

Something is tracking that your session previously belonged to another user so that the "Logged in as XYZ ([email protected])" message can be displayed in the Salesforce UI.

I suspect this would be cookie based. If this is the case, you could try and isolate it by tracking the cookie changes when you login 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');