7

I know, we can query LoginHistory to find out who has logged in today - but that doesn't tell us who logged in and is STILL logged in ...

Thanks!

1
  • You can see the active sessions on the server, but those users may not actually still be logged in. This is due to the stateless nature of HTTP. The server can't be guaranteed to know when you've logged out, unless you do so explicitly via the Logout command. The server can only tell you if there's still a usable session token for a user.
    – sfdcfox
    Feb 6, 2015 at 18:41

2 Answers 2

3

You can see currently logged in users in Setup > Security Controls > Session Management. For more information, have a look here: https://help.salesforce.com/htviewhelpdoc?id=security_user_session_info.htm&siteLang=en_US

You can also use the AuthSession object to use this information in your code: https://www.salesforce.com/developer/docs/api/Content/sforce_api_objects_authsession.htm

3
  • 1
    That's as close as we can get, anyways. If I close my browser, I am logged out (i.e. I will probably be required to sign in when I next open salesforce.com), but salesforce.com still has an active session for me until it naturally expires (e.g. 2 hours).
    – sfdcfox
    Feb 6, 2015 at 18:40
  • Just out of interest, it does close off a session if you use the logout button, right? I know there's barely anyone who bothers.. :-) Feb 6, 2015 at 18:41
  • Certainly. Using the API's logout() call, or using the Logout link in the top-right corner, purges the session from the server immediately. Only then can the server know for sure that you're not logged in. I don't think I've ever intentionally used the Logout link manually (I know, I know...).
    – sfdcfox
    Feb 6, 2015 at 18:42
4

You can query the AuthSession object to get the active sessions, which will include any that haven't ended due to timeout or the user explicitly logging out.

There will generally be multiple AuthSession records per user because a Visualforce session is created in addition to a normal UI session. There will also be non-interactive sessions for users accessing Salesforce through the API, including other applications that access Salesforce on behalf of the user using OAuth.

Finally, users may log in multiple times throughout the day creating multiple sessions which haven't timed out yet.

So if you want to get the best estimate of the number of Users accessing Salesforce through the web interface, this is probably your best bet:

SELECT
  COUNT_DISTINCT(LoginHistory.UserId)
FROM
  AuthSession
WHERE
  LoginType = 'Application' AND
  SessionType = 'UI'

You must log in to answer this question.