I have a REST access token and would like to use that access token in my PartnerConnection ConnectionConfig to make a Bulk API call. It does not seem to work as I get an message to set my Service Endpoint. Please assist if it is possible to make a SOAP call from a REST access token?And how I can do it.
2 Answers
Yes you need to provide the service end point, if you logged in with Salesforce WSC (Web Service Connector) this is usually handled for you or returned in the LoginResult if you took the manual login route. If not you can set it manually like so.
ConnectorConfig partnerConfig = new ConnectorConfig();
partnerConfig.setServiceEndpoint("https://yourinstance.salesforce.com");
partnerConfig.setSessionId(yourSessionId);
ParnterConnection partnerConnection = Connector.newConnection(partnerConfig);
Note: Its not usually a good idea to hard code your instance name. I assume when forming the REST URL's you've already resolved this in a way that is satisfactory for your situation.
thanks for your advice here is the code the worked for me:
ConnectorConfig partnerConfig = new ConnectorConfig();
partnerConfig.setAuthEndpoint("https://test.salesforce.com/services/Soap/u/27.0");
partnerConfig.setServiceEndpoint("https://cs17.salesforce.com/services/Soap/u/");
partnerConfig.setSessionId(sessionProvider.getAccessToken());
new PartnerConnection(partnerConfig);