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
David Lee 8David Lee 8 

Java Partner WSDL - INVALID_SESSION_ID - Invalid Session ID found in SessionHeader: Illegal Session.

I have a Java application that's connecting to Salesforce using PartnerConnection.
Queries work fine at first but overnight it seems like the session expires/becomes invalid. What's the best way to check if the session is valid without performing a query?
doesn't seem to work. Once I catch the error, would creating a new PartnerConnection work?:
catch (UnexpectedErrorFault uef) {
    if (uef.getExceptionCode() == ExceptionCode.INVALID_SESSION_ID) {
        this.connection = new PartnerConnection(this.getConfig());
James LoghryJames Loghry
Yeah, you'll need to renew your sessions at some point.  The best way to handle it is likely to catch the invalid session id and then re-login / grab a new session at that point.  Alternatively, you could keep calling login, which will use the same session if one is available, but you would eat up additional api calls with that approach.