function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
harsha B R 9harsha B R 9 

How to find the currently logged in users in the organisation.

Hello Everyone,

Is there any way to find out the currently logged in users of the org.

Requirement :- When a lead is created,I need to assign the lead dynamically to only to the logged in users(Need to fetch all the logged in users of the org programatically).

Salesforce has mentioned in one of the ideas that they have implemented it -

Executed the SOQL query - Select a.UsersId, a.IsCurrent, a.UserType, a.SourceIp, a.SessionType, a.SessionSecurityLevel, a.ParentId, a.NumSecondsValid, a.LoginType, a.LastModifiedDate, a.Id, a.CreatedDate From AuthSession a

But,it returned only my user record.It didn't not returned the other users who have logged in the orge.

All the logged in users can be accesed at the UI level --> security controls --> session Management.

Any idea/help is appreicated.

Thanks & Regards,
Harsha BR 
Hi Harsha,

You can try following query. test it on developer console first.
SELECT  Id, createddate, IsCurrent, UsersId, LogoutUrl, SourceIp FROM AuthSession WHERE IsCurrent = true

Please mark this answer as SOLVED and BEST ANSWER if it helps you.

Yogesh More
Salesforce consultant || Salesforce Developer || || Skype:-yogesh.more44
Hi Harsha,

Salesforce do not ask to Query currently Logged in user, please try with this block of code:
id loggedInUser = Userinfo.getUserId();

It will provide you the Id of currently logged in user. If you need more fields please visit this link (

Skype: gaurav62990