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
jingzhijingzhi 

How to identify that a user has login or logout Salesforce in App?

Salesforce SessionId is very tricky:
1. Different pages may have different SessionId ({!$Api.Session_ID});
2. Logout and then Login again may get the same SessionId as last Login;

Then, how to identify that a user has login again or logout Salesforce in our App?
SuperfellSuperfell
Take the sessionId, make an api call with it.
jingzhijingzhi
Simon,

Thanks for your reply!
But, you made a misunderstand about my question.
In our project, we use SessionId from VF to call back Salesforce Web Service. It works well.

However, on our java servlet side, We cannot identity when a user logout Salesforce or
relogin Salesforce by the SessionId. The point is we need the logout event or login event
in our servlet.

For example,
Obama is supposed one user of our application on Salesforce.
Obama login Salesforce, and do some operation on our application, then logout;
After a while, Obama login again.

Currently, on our java servlet side, we haven't found any way which decides Obama logout Salesforce once a time.
We need this information to do some stuff.

Any way?
SuperfellSuperfell
As i'm sure you're aware trying to track session logout/expiry on web applications is a loosing battle.

If the users logs out and back in again, what does it matter? what if you just logged into salesforce in the morning and used it all day vs, logged in the morning and used it for an hour, then logged back in again in the afternoon, is that really 2 different scenarios ? what if i log in from 3 different browsers?
jingzhijingzhi
Simon,

Really.
Login & Relogin, that's 2 different scenarios in our Application.
For clearly speaking, let's use a simple graph:) to describe the senario:
                   
                                Web browser   --------session1----------  Java App Server
                                        :
                                    session2
                                        :
                                SF Server

there are 2 sessions in this single application.
When user logout Salesforce, the session2 is released, while session1 is still live.
Thus, when user login Salesforce again, a new SF session2 will be started with the
old session1 is still active. It's inconsistency. 

Actually, we set some stuff in session1, and these stuff should be released when
every time a user logout Salesforce.

We hope that these 2 sessions should be synchronized through programming skills.

Thanks
SuperfellSuperfell
Its not possible to detect this, you should be linking your data to users not sessions. Frankly i think you've lead yourself down a web unfriendly path.

Feel free to post an idea on the ideaexchange for this, the more compelling your usecase the better.
jingzhijingzhi
Good suggestions!
I'll reconsider our implementation.
:smileyhappy: