invalidateSessions()

Ends one or more sessions specified by a sessionId.

Syntax

InvalidateSessionsResult = connection.invalidateSessions(string[] sessionIds);

Usage

Use this call to end one or more sessions.

You can also use logout() to end just one session, the session of the logged-in user.

Sample Code—Java

public void invalidateSessions() {
    String[] sessionIds = new String[2];
    sessionIds[0] = connection.getConfig().getSessionId();
    // a vlaid session ID, but not for the current one
    sessionIds[1] = "00DD0000000FKDk!AQYAQPcBSDy8B1Zml.ZrOB_" +
        "6x0fjHaMGzUzHKEd_Sd3LVJDOEtjjG884DKBGn7cEu.5rMllkvq" +
        "QSD.DzHnvPAn4SBskeka5l";
    try {
      InvalidateSessionsResult[] results = 
          connection.invalidateSessions(sessionIds);
      for (InvalidateSessionsResult result : results) {
        // check results for errors
        if (result.isSuccess()) {
          System.out.println("Success.");
        } else {
          Error[] errors = result.getErrors();
          if (errors.length > 0)  {
            StatusCode code = errors[0].getStatusCode();
            String message = errors[0].getMessage();
            // handle error. We just print the first error
            // out for sample purposes.
            System.out.println("Error code: " + code);
            System.out.println("Error message: " + message);
          }
        }
      }
    } catch (ConnectionException ce) {
      ce.printStackTrace();
    }
  }

Sample Code—C#

public void InvalidateSessions(string [] sessionIds) {
    try {
        InvalidateSessionsResult[] results;
        results = binding.InvalidateSessions(sessionIds);
        for (InvalidateSessionsResult result in results) {
            // check results for errors 
    
            if (!result.Success) {
                StatusCode code = result.Errors[0].StatusCode;
                string message = result.Errors[0].Message;
                // handle error 
    
                ...
            }
        }
    }
    catch (Exception e) {
        Console.WriteLine("Unexpected error encountered while trying to logout:\n\n{0}",
             e.Message);
        // handle exception 
    
        ...
    }
}

Arguments

Name Type Description
sessionIds string[] One or more sessionId strings. Limit 200. You can obtain your sessionId from the SessionHeader.

Response

InvalidateSessionsResult[]

Faults

UnexpectedErrorFault

© Copyright 2000–2012 salesforce.com, inc. All rights reserved.
Various trademarks held by their respective owners.