3

How to control the Timeout for Enterprise WSDL for Salesforce integration.

1 Answer 1

2

The session of Enterprise WSDL is governed by Session Settings by your administrator .You can navigate to SetUp | Security Controls | Session Settings to set the timeout value

enter image description here

The default is 120 minutes (two hours) and maximum values is 12hrs(Longer session time outs can be not safe depending on the business.)

If you make an API call, the inactivity timer is reset to zero.

There are different mechanisms to prevent the session being timed out for API calls .

Store the current time of the system + Time out time in a variable when a call is made and when next call is made compare the time with variable value to find if you need to make a login() call again .

Below is an example code demonstration for that

  /**
  * This method is used to log in to salesforce and set the
  * private class variables for the wrapper, including the
   * session ID.
  */  

public void login() throws UnexpectedErrorFault, InvalidIdFault,
                       LoginFault, RemoteException, 
                       ServiceException {

resetBindingStub();
LoginResult loginResult = binding.login(username, password);
this.nextLoginTime = System.currentTimeMillis() + 
                     (this.sessionlength * 60000);

this.binding._setProperty(SoapBindingStub.
                          ENDPOINT_ADDRESS_PROPERTY,
                          loginResult.getServerUrl());
this.sessionId = loginResult.getSessionId();
this.serverUrl = loginResult.getServerUrl();

  // Create a new session header object and set the
  // session id to that returned by the login
 SessionHeader sh = new SessionHeader();
 sh.setSessionId(loginResult.getSessionId());
 this.binding.setHeader(new 
 SforceServiceLocator().getServiceName().getNamespaceURI(),
   "SessionHeader", sh);
}

Method to check Session is active or not

/**
* This method returns true if a login to Salesforce is
* necessary, otherwise false. It should be used to check the
* session length before performing any API calls.
*/  

private boolean loginRequired() {
    if (sessionId == null || sessionId.length() == 0) 
    return true;
  return !isConnected();
}

/**
* This method checks whether the session is active or not
* @return boolean
*/  

  public boolean isConnected() {
     return System.currentTimeMillis() < nextLoginTime;
  }

EDIT>>>

To set timeout values for each profile you can follow below

https://help.salesforce.com/HTViewHelpDoc?id=users_profiles_session.htm

Ask your admin to create a separate profile for integration where you can specify session time out

enter image description here

3
  • 1
    Thanks Mohith for the detailed explanation. My follow up question then is, this session setting will then be effective throughout the entire org for all users, isn't it. Is there a way to control the timeout for the integration user only? Feb 22, 2016 at 2:00
  • @DeepSinghal Just answered .You can create a separate profile and do session settings .Thanks Feb 22, 2016 at 2:24
  • @DeepSinghal Why dont you mark the answer as answered so it helps others Feb 22, 2016 at 4:50

You must log in to answer this question.

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