I trying display number of currently logged users to the community in my lightning component. Now I using below SOQL query:

List<AggregateResult> numberCurrentlyLogged = [SELECT COUNT_DISTINCT(LoginHistory.UserId) number FROM AuthSession WHERE LoginType = 'Application' AND SessionType = 'UI'];

this query return count of all currently logged user to ORG not to community.

Any idea?


Add this (or similar - you may have to query and check for a value corresponding to your community):

UserType = 'Customer Portal User'

From AuthSession:


Type picklist

Properties Filter, Group, Restricted picklist, Sort

Description The kind of user for this session. Types include Standard, Partner, Customer Portal Manager, High Volume Portal, and CSN Only.

| improve this answer | |
  • This is a part : ) I have 3 communities and I need display on it inform how many users are currently logged to this community. For example I have 2 communities A and B on A logged 5 user and display 5 but on B logged 3 and display 3 ; ) – JJanek Jun 23 '17 at 10:16

I resolve this issue base on AuthSession - user type and sesion. Added single permset to acces in community - so I need add it to the user. I put all user with PermSet to the Set and loop for agregate resoult from authSesion LoginHistory.UserId. And If in Set and in AuuthSession add 1 to the counter.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.