+ Start a Discussion
Sinan BunniSinan Bunni 

SOQL query to find out Logged in users

Hi all,
Is there a way to write a SOQL query to find out who is logged in or not in salesforce? I tried to use the combination of AuthSession with User sObjects but there was no success.
Thank you for your input, Sinan
Sfdc CloudSfdc Cloud
Hi Sinan,

Could you share your code.

Sinan BunniSinan Bunni
Hi Sfdc Cloud,

I have tried to think of it this way, that if the user has been authenticated successfully, the user will have an Id and a UsersId (i.e. from the AuthSession)...

List<User> usersLs = [select Id, Username from User];
Map<Id, User> usersMp = new Map<Id, User>(usersLs);

List<AuthSession> authLs =  [select UsersId, Id from AuthSession];
//Map<Id, AuthSession> authMp = new Map<Id, AuthSession>(authLs);

for (AuthSession authUser : authLs) {
    if (usersMp.containsKey(authUser.UsersId)) {

The above code will give me the users who have logged in successfully, the problem with this code is simply, there is no time indication of how long the user has been logged and whether the session is active or not.#

Thank you, Sinan
Sfdc CloudSfdc Cloud
Hi Sinan,

First of all Sorry for late response.I was stucked due to internet connectivity Issue.
Query on Authsession will return only Session valid untill time (NumSecondsValid),but based on activity by user it will change.So we couldnt fatch how long user has been logged in org.

Second thing If we will query on Login history object based on where condition UserId (map which u have created ).It will only return LoginTime but there is no field with name logout on Login History.

So i think that we should raise this Idea at Idea Portal.

Sinan BunniSinan Bunni
Hi Sfdc,
thank you for your prompt reply - how will someone be able to post the idea to the Idea Portal.

What I am trying to do is to design a round robin algorithm for automatic Case(s) assignment, I have implemented the algorithm but simply, our support team would like to be able to assign Case(s) to 'Logged In' individual only.

Thank you for your input and time,

Kind Regards, Sinan