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
java devjava dev 

How to detect whether the session is expired or not, & if expired, how to set it back

Hi all,

    I have to write an application which will query salesforce fo revery 5 mins & get the data and put it on my target Database.

But after 2 hours running continuously, I am getting "Invalid session Id" exception & my session is getting timed out. I know the default session time period is 2 hrs for salesforce.

So ,1) how to detetc whether the session is expired or not?

2) If session is expired, how to set it back dynamically, So i need to login again?

Currently what iam doing is, I am storing my login time, & when ever i am queying for salesforce, I am checking whethet the time of querying is 1hr 50min from login time. If yes i am again loging in.

so, 3) what about my previous session?
4) Is it good to keep that sessions open?

Any one please help me. I want this urgently.

Thank you,
Sudheer Tumu.