1

SOAP API is not able to authenticate using username/password+security only on sandboxes. I tried to authenticate the username/pwd+Security token using mavens mate and they seem to be correct.

Could this be due to TSL disablement? If so, what is the fix for this? I see fixes around using appropriate Java versions to support this change, but what should I do from Apex to allow SOAP logins?I am getting '

Web service callout failed: WebService returned a SOAP Fault: INVALID_LOGIN: Invalid username, password, security token; or user locked out. faultcode=INVALID_LOGIN faultactor=' exception which does not give any hint about the TLS disablement.

partnerSoapSforceCom.Soap con = new partnerSoapSforceCom.Soap();
partnerSoapSforceCom.LoginResult loginResult = con.login('username', 'passwordtoken');

Please note that it is happening only for sandboxes and not production. Any ideas, appreciated.

  • 2
    Shalini are you sure you are using test.saleforce.com ? What does Salesforce user record show in login history ? – Mohith Shrivastava Mar 28 '17 at 23:51
  • if it's a tls issue, you will get something similar to below error Require TLS 1.1 or higher – night crawler Mar 28 '17 at 23:53
  • are you using enterpirse wsdl's, login () method? – night crawler Mar 28 '17 at 23:55
  • I have updated my question with the code i am using – Shalini SF Mar 29 '17 at 0:12
  • 1
    Where are you specifying the URL that the class is using within the .login() method? The URL for a sandbox org is test.salesforce.com and production is login.salesforce.com - if you are using auto-generated code, check the URL. – Mark Pond Mar 29 '17 at 1:07
1

From the example code you provided, it looks like you are accessing the SOAP Partner API from Apex generated via wsdl2apex.

You will need to adjust the initial endpoint of the login call for a sandbox. Sandbox logins need to go via test.salesforce.com. All others (except preproduction) start with login.salesforce.com.

After you complete the login, use the serverUrl from the login result to set the endpoint.

partnerSoapSforceCom.Soap partner = new partnerSoapSforceCom.Soap();

// Sandbox
partner.endpoint_x = 'https://test.salesforce.com/services/Soap/u/39.0';
// Production/Developer 
//partner.endpoint_x = 'https://login.salesforce.com/services/Soap/u/39.0';

partnerSoapSforceCom.LoginResult lr = partner.login('user@example.com', 'Password' + 'SecurityToken');
partnerSoapSforceCom.SessionHeader_element header = new partnerSoapSforceCom.SessionHeader_element();
header.sessionId=lr.sessionId;
partner.SessionHeader=header;
partner.endpoint_x = lr.serverUrl;

partnerSoapSforceCom.QueryResult qr = partner.Query('Select Id, Name from Account limit 1');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.