function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Damien_Damien_ 

Issues connecting with the Partner WSDL

Right now I'm just trying to establish a connection between my java app and Salesforce, but it isn't working out very well.  For some reason on my connection = new PartnerConnection(config); line I always error.

 

[ApiFault  exceptionCode='INVALID_LOGIN' exceptionMessage='Invalid username, password, security token; or user locked out.'

 

I have already confirmed that my username/password/security token are all correct.

 

public static void main(String[] args)  {   

ConnectorConfig config = new ConnectorConfig();   

config.setUsername("MYLOGIN");   

config.setPassword("MYPW&MYTOKEN");       

PartnerConnection connection;

try    {        

connection = Connector.newConnection(config);  

 } catch (ConnectionException e)    {     

// TODO Auto-generated catch block      e.printStackTrace();    }   }

Best Answer chosen by Admin (Salesforce Developers) 
Damien_Damien_

I figured it out... something dumb of course.  I had to remove the ampersand from my password section.

 

config.setPassword("MYPW&MYTOKEN"); 

 

to

 

config.setPassword("MYPWMYTOKEN"); 

All Answers

pkurapkura

Please set config.setPassword ("mypassword") only ...no token. Make sure the user is not locked out by web login at http://login.salesforce.com. Once your'e sure you're not locked out, you can try as I said.

Damien_Damien_

I already tried this, it then told me that I need a security token in the error log.

pkurapkura

I think you're not setting the auth endpoint. This is what I use normally:. I define the endPoint, userName, Password in a property file and pass them to this method.  See if it works for you.

 

private ConnectorConfig createConnectionConfig(String endPoint, String userName, String password) throws ConnectionException {

 ConnectorConfig connectionConfig = new ConnectorConfig();
        if ( endPoint != null && userName != null && password != null ){
            connectionConfig.setServiceEndpoint(endPoint);
            connectionConfig.setAuthEndpoint(endPoint);
            connectionConfig.setUsername(userName);
            connectionConfig.setPassword(password);
            return connectionConfig;
        }

}

Damien_Damien_

Well, maybe my endpoint isn't correct.  How do I determine what this should be?  From what I've read, if its blank it should be able to figure it out anyways.  I've seen a couple of things that looked about right, but when I used them it didn't work out either.

pkurapkura

Is it prod or sandbox env ? Do you normally login using web at login.salesforce.com ?

If you're using API, it should be of the form endpoint = https://login.salesforce.com/services/Soap/u/22.0 (the version can vary). if you're using sandbox env. use https://test.salesforce.com/services/Soap/u/22.0.

 

I'm assuming you're using partner wsdl for connection. If you're using enterprise the endpoint varies.

Damien_Damien_

It errored, but told me I had to have hte endpoint as servers/Soap/c/22.0 instead of the 'u'.  After making that change, I also removed the security token and got the error:

 

[LoginFault [ApiFault  exceptionCode='LOGIN_MUST_USE_SECURITY_TOKEN' exceptionMessage='Invalid username, password, security token; or user locked out. Are you at a new location? When accessing Salesforce--either via a desktop client or the API--from outside of your company’s trusted networks, you must add a security token to your password to log in. To receive a new security token, log in to salesforce.com at http://login.salesforce.com and click Setup | My Personal Information | Reset Security Token.']

 

Then after that I put the security token back in:

 

[LoginFault [ApiFault  exceptionCode='INVALID_LOGIN' exceptionMessage='Invalid username, password, security token; or user locked out.']]

 

This exact same info works when I'm trying to bring the instance into Eclipse (I'm doing this on a Developer org btw).

Damien_Damien_

Nevermind... I think the /c/ was the instance of hte project I was testing using another way to login.  My partner login I used the /u/ and got the same issues.

pkurapkura

u indicates you're using enterprise wsdl to connect to salesforce. Based on the error, I think the endpoint is wrong. You're getting the security token from a prod instance (by logging in at login.salesforce.com) and trying to use that security token with a dev org (which cannot validate that token).

1) Try to login to test.salesforce.com instead of login.salesforce.com and get the security token.

You can use this link http://success.salesforce.com/apex/questiondetail?qId=a1X30000000HxnYEAS for reference.

Damien_Damien_

Yea, I had a couple of different projects trying to get any of the enterprise/partner working.  I looked at the wrong one there.  I am using a Developer org though and not a Sandbox so the login.salesforce is correct.

Damien_Damien_

I figured it out... something dumb of course.  I had to remove the ampersand from my password section.

 

config.setPassword("MYPW&MYTOKEN"); 

 

to

 

config.setPassword("MYPWMYTOKEN"); 

This was selected as the best answer
wittywitty

Is there any solution to avoid the security token. I don't want to use the security token, because if the password is being changed again i have to get that newly generated security token from the mail id of the user.

dphilldphill
I know there is a setting you can disable so that you no longer need security tokens. I can't find it atm but I'm sure you could with a google search. You can alternatively set it up so that you don't need to change the password on the User every so often.