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 have been browsing on-line more than three hours lately, yet I never discovered
    any fascinating article like yours. It is lovely price sufficient for me.
    In my view, if all webmasters and bloggers made just right
    content as you probably did, the web will be much more useful than ever before.

  2. Hey I know this is off topic but I was wondering
    if you knew of any widgets I could add to my blog that automatically tweet my newest twitter
    updates. I’ve been looking for a plug-in like this for quite some time and was hoping
    maybe you would have some experience with something like this.
    Please let me know if you run into anything.
    I truly enjoy reading your blog and I look forward to your new updates.

  3. These are genuinely fantastic ideas in concerning blogging.
    You have touched some pleasant things here. Any way keep up wrinting.

  4. No matter if some one searches for his vital thing, so he/she desires
    to be available that in detail, therefore that thing is
    maintained over here.

  5. Hello there! Do you know if they make any plugins to safeguard against hackers?
    I’m kinda paranoid about losing everything I’ve worked hard
    on. Any recommendations?

  6. Excellent post. I was checking continuously this blog and
    I am impressed! Very helpful info particularly the remaining section ๐Ÿ™‚ I deal with such
    information much. I was seeking this certain info for
    a long time. Thanks and good luck.

    Also visit my web page – wm casino ios

  7. I really love your site.. Great colors & theme. Did you make
    this amazing site yourself? Please reply back as I’m attempting to
    create my very own website and want to know where you got
    this from or just what the theme is called. Appreciate it!

    Feel free to visit my webpage id test ok388

  8. I have been surfing online more than 3 hours today,
    yet I never found any interesting article like yours.
    It’s pretty worth enough for me. In my view,
    if all web owners and bloggers made good content as you did, the internet will be
    a lot more useful than ever before.

    Also visit my blog post – pussy888 ios download

  9. I do not even know how I ended up here, but I thought this post was good.
    I do not know who you are but definitely you’re going to a famous blogger if you are not already ๐Ÿ˜‰ Cheers!

    Feel free to surf to my web page … test mega888

  10. Wow that was unusual. I just wrote an extremely long comment but after I clicked submit my
    comment didn’t show up. Grrrr… well I’m not writing all that over again. Anyway, just wanted to say superb blog!

    Have a look at my page agen ace333

  11. I was recommended this web site by my cousin. I’m not sure whether this post is written by him as nobody else know such detailed about
    my trouble. You’re wonderful! Thanks!

    my blog – epicwin

  12. With havin so much content do you ever run into any issues
    of plagorism or copyright infringement? My site has a lot
    of unique content I’ve either written myself or outsourced but it looks like a lot of it is popping it up
    all over the web without my agreement. Do
    you know any techniques to help reduce content from
    being ripped off? I’d truly appreciate it.

    My blog post; joker888 apk free download

Comments are closed.