How to check whether a user (not current User) has active logged in session or not

The AuthSession object keeps each non-guest user session in your organization. Here is full detail of object: https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_authsession.htm

List<AuthSession> auth = [SELECT Id , IsCurrent, SessionType, CreatedDate, LoginGeoId, NumSecondsValid  FROM AuthSession WHERE UsersId='0051b000001ZRpQ'];

Check the size of auth if it’s greater than zero and IsCurrent is true then session is active otherwise not.

if(auth.isEmpty() == false && auth[0].IsCurrent ){
    system.debug('yes, it is current user session');
}else{
    system.debug('No, it is not current user session');
}

23 thoughts on “How to check whether a user (not current User) has active logged in session or not”

  1. I like the helpful information you provide in your articles.

    I’ll bookmark your blog and check again here frequently.
    I’m quite sure I will learn lots of new stuff right here!
    Best of luck for the next!

    Also visit my website; download rollex11 original – 918kiss-m.com

  2. Have you ever thought about adding a little bit more than just your articles?
    I mean, what you say is fundamental and all. Nevertheless think about if you added some great photos or video clips to give your posts
    more, “pop”! Your content is excellent but with images and videos,
    this website could certainly be one of the greatest in its field.
    Very good blog!

Comments are closed.