1

I'm trying to build a simple java client program using the partner WSDL. I build stubs from the Partner WSDL file. I downloaded the WSC .jar file and added it to my build path. I'm still getting Connector cannot be resolved and PartnerConnection cannot be resolved.

Anyone know where I should go for those or why I don't have them in my project when I have the stubs from the partner WSDL and the force-wsc-44.0.0.jar?

import com.sforce.soap.partner.*;
import com.sforce.soap.partner.sobject.*;
import com.sforce.ws.*;
import com.sforce.ws.ConnectorConfig;

class SalesforceHelper {

    public SalesforceHelper () {

        ConnectorConfig config = new ConnectorConfig();
        config.setUsername("username");
        config.setPassword("password");

        PartnerConnection connection = Connector.newConnection(config);
    }

}
1
  • You can use the maven repository for this : https://mvnrepository.com/artifact/com.force.api/force-partner-api to create a PartnerConnection Nov 2 '19 at 12:27
0

I am sure the example in the documentation is missing something there as those classes do not exist in the client you generate from WSDL or in the wsc.jar itself.

Below is the approach, how I have used to connect using SOAP API with my Enterprise WSDL, you may just replace the enterprise package with partner package here and that should work:

com.sforce.soap.enterprise.Soap soap = new SoapProxy();
com.sforce.soap.enterprise.SoapBindingStub.stub = new SoapBindingStub();
com.sforce.soap.enterprise.LoginResult;
com.sforce.soap.enterprise.QueryResult qResult

loginResult; = soap.login(userName, password);
stub._setProperty(SoapBindingStub.ENDPOINT_ADDRESS_PROPERTY, loginResult.getServerUrl());
stub.setHeader("urn:enterprise.soap.sforce.com", "SessionHeader", new SessionHeader(loginResult.getSessionId()));
...
...
qResult = stub.query(IConstants.query);
0
0

I got it to connect and query but I can't get the data. SF Docs say there's a getField() method but there ain't...

import com.sforce.soap.partner.*;

import com.sforce.soap.partner.sobject.*;

public class MyMain {

com.sforce.soap.partner.SoapBindingStub stub = null;

public static void main(String[] args) {
    try {
        MyMain helper = new MyMain();
        helper.queryContact();

    } catch (Exception ex) {
        ex.printStackTrace();
        System.out.println(ex); 
    }
}

public MyMain() throws Exception {
    com.sforce.soap.partner.Soap soap = new SoapProxy();
    stub = new com.sforce.soap.partner.SoapBindingStub ();
    com.sforce.soap.partner.LoginResult loginResult = soap.login("zzz@zzz.com", "zzzzzzasHO9zzbYIoDH5kaujICoGBA");
    stub._setProperty(SoapBindingStub.ENDPOINT_ADDRESS_PROPERTY, loginResult.getServerUrl());
    stub.setHeader("urn:enterprise.soap.sforce.com", "SessionHeader", new SessionHeader(loginResult.getSessionId()));

    //com.sforce.soap.partner.QueryResult qResult
    System.out.println(loginResult);             
}

public void queryContact() throws Exception {
    String soqlQuery = "SELECT FirstName, LastName FROM Contact limit 1";
    QueryResult qr = stub.query(soqlQuery);
    SObject[] recordList = qr.getRecords();
    for (int i = 0; i < recordList.length; i++) {
        SObject contact = recordList[i];
        //Object firstName = contact.getField("FirstName");
        //Object lastName = contact.getField("LastName");   
        //System.out.println(firstName + " " + lastName);
        System.out.println(contact);
    }
}

}

0

I believe I figured it out. I'm so used to work in Eclipse and simply building stubs there. SF does have a value as. The wsc jar isn't just an add-on library, it has facilities for building value-add classes and methods. You can't skip that step and just use Apache axis wsdl2java.

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.