1

I have currently developed a Java API client that connect against the Salesforce instance of my company. Using the following tutorial:

https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_calls_login.htm

The issue I am having is, that I would like to disable the session time out for this API user, I changed it into the Salesforce Session management settings but the maximum value is 12 hours but I would like that the session would never expire...

I read on this question that OAuth can be used for this purpouse...

would it be enough by changing the AuthUrl to an OAuth endpoint ?

    String username = "[email protected]";
    String password = "testi8Pforce8inNUD6i8P3YxMUJNMvkyjQa";

    // Is this what I should change? from Soap to an OAuth endpoint?
    String authEndPoint = "https://login.salesforce.com/services/Soap/c/35.0/"; 

    ConnectorConfig config = new ConnectorConfig();

    config.setUsername(username);
    config.setPassword(password);
    config.setAuthEndpoint(authEndPoint);

Is this the right approach ? any help would be highly appreciated

2 Answers 2

1

OAuth endpoint needs to be: https://login.salesforce.com/services/oauth2/token

Note for Sandbox it would be: https://test.salesforce.com/services/oauth2/token

Read up on: Username Password OAuth Flow

0

I would like to add another alternative that work quite well for me as well.

I discovered the Java interface "SessionRenewer" that can be implemented and will be called each time that the API call leads to an "INVALID_SESSION_ID" error.

The idea is something like this:

String username = "[email protected]";
String password = "testi8Pforce8inNUD6i8P3YxMUJNMvkyjQa";
String authEndPoint = "https://login.salesforce.com/services/Soap/c/35.0/"; 

ConnectorConfig config = new ConnectorConfig();

config.setUsername(username);
config.setPassword(password);
config.setAuthEndpoint(authEndPoint);
config.setSessionRenewer(new SalesforceSessionRenewer()); // This class will be called 

And the Interface implementation

public class SalesforceSessionRenewer implements SessionRenewer {

/**
 * This method is called when an expired session is detected. The returned object needs to be a valid SessionRenewAlHeader
 * so that the current request can be re-tried. If the return value is null current call shall not be retired even though the
 * session has been refreshed.
 */
public static final javax.xml.namespace.QName SESSION_HEADER_QNAME = new javax.xml.namespace.QName("urn:partner.soap.sforce.com", "SessionHeader");
@Override
public SessionRenewalHeader renewSession(ConnectorConfig connectorConfig) throws ConnectionException {

    connectorConfig.setSessionId(null);

    EnterpriseConnection connection =  new EnterpriseConnection(connectorConfig);

    SessionRenewalHeader header = new SessionRenewalHeader();
    header.name = new QName( "urn:enterprise.soap.sforce.com", "SessionHeader" );
    header.headerElement = connection.getSessionHeader();

    return header;
    }
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .