Access Forec.com from Java using Axis2 Enterprise WSDL

Steps to create a library that can access Salesforce from Java based on nterprise WSDL

1. Download Enterprise WSDL from the "Development> API" link & save it as enterprise.wsdl

2. Prepare a library to generate Java classes from wsdl file

-Apache Axis2 "axis2-1.3-bin.zip" Where to get it: https://archive.apache.org/dist/ws/axis2/1_3/ After extraction, lib / and everything below is required ・ Force-wsc-34.0.jar Where to get it: http://mvnrepository.com/artifact/com.force.api/force-wsc/34.0

・ Js-1.7R2.jar Where to get it: http://mvnrepository.com/artifact/rhino

・ ST-4.0.8.jar Where to get it: http://www.stringtemplate.org/download/

3. After downloading the above jar file, copy it to axis2-1.3 / lib / and compile it.

Place enterprise.wsdl under axis2-1.3 / bin / and execute the command $ sh wsdl2java.sh -Eofv -g -uw -u -uri enterprise.wsdl

4. Confirmation

Java source files are generated under the com directory

5. Operation check

After generating a suitable Java project in Eclipse, put all the above jar files in the clasp path and confirm that you can authenticate and execute SOQL with the following source

import com.sforce.soap.enterprise.LoginResult;
import com.sforce.soap.enterprise.QueryResult;
import com.sforce.soap.enterprise.SessionHeader;
import com.sforce.soap.enterprise.SforceServiceStub;
import com.sforce.soap.enterprise.sobject.Account;
import com.sforce.soap.enterprise.sobject.SObject;

import org.apache.axis2.client.Options;
import org.apache.axis2.transport.http.HTTPConstants;

public class TestLogin {

    public static void main(String[] args) throws Exception {
        SforceServiceStub stub = new SforceServiceStub();
        Options options = stub._getServiceClient().getOptions();
        options.setProperty(HTTPConstants.MC_ACCEPT_GZIP, Boolean.TRUE);
        options.setProperty(HTTPConstants.MC_GZIP_REQUEST, Boolean.TRUE);

        LoginResult lr = stub.login("[email protected]", "xxxx", null);

        SessionHeader sh = new SessionHeader();
        sh.setSessionId(lr.getSessionId());

        stub = new SforceServiceStub(lr.getServerUrl());
        options = stub._getServiceClient().getOptions();
        options.setProperty(HTTPConstants.MC_ACCEPT_GZIP, Boolean.TRUE);
        options.setProperty(HTTPConstants.MC_GZIP_REQUEST, Boolean.TRUE);

        QueryResult qr = stub.query("select Name, numberOfEmployees, Id, Industry from Account", sh, null, null, null);

        System.out.println("Query has " + qr.getSize() + " records total");

        SObject[] sObjects = qr.getRecords();

        for (int i = 0; i < sObjects.length; i++) {
            Account sObject = (Account) sObjects[i];
            System.out.println(i + "\t: [" + sObject.getId() + "][" +
                sObject.getName() + "]");
        }
    }
}

Recommended Posts

Access Forec.com from Java using Axis2 Enterprise WSDL
Access API.AI from Java
Using Docker from Java Gradle
Access Teradata from a Java application
Sample code using Minio from Java
Data processing using stream API from Java 8
Using JavaScript from Java in Rhino 2021 version
Connect from Java to MySQL using Eclipse
Call Java methods from Nim using jnim
Access protected fields from grandchildren (Java / PHP)
Run Rust from Java with JNA (Java Native Access)
Try accessing the dataset from Java using JZOS
Ssh connect using SSHJ from a Java 6 app
Access modifier [Java]
Output the maximum value from the array using Java standard output
[Java] Text extraction from PowerPoint (ppt) using Apache POI
Using the database (SQL Server 2014) from a Java program 2018/01/04