Wednesday, 21 December 2011

Check Salesforce connection by java

Check Salesforce connection by java
This task use java to check if Salesforce account (includes username, password, security token) is valid or not.
Check by logging in and logging out
Call check method with try ... catch. If exception is thrown, account is not valid.
 public void check(String username, String password, String token) throws Exception {
        ConnectorConfig cc = new ConnectorConfig();
        URL loginUrl = new URL(Connector.END_POINT);
        String serverUrl = "";
        cc.setAuthEndpoint(serverUrl + loginUrl.getPath());
        cc.setServiceEndpoint(serverUrl + loginUrl.getPath());
        PartnerConnection partner = Connector.newConnection(cc);
        LoginResult loginResult = partner.login(username, password + token);
        if (loginResult.getPasswordExpired()) {
         partner = null;
         throw new Exception("User has expired password");

  Protected by Copyscape Online Copyright Protection

No comments:

Post a Comment