flectSalesforce

Return to index link to github

Overview

JavaDoc

Salesforce SOAP API wrapper.

Following features are supported

  • Query
  • Create, Update, Delete, Upsert
    • Like SQL, you can update data by insert, update, and delete statement.
  • Retrieving metadata
  • Bulk API
    • You can do bulk upsert directly from SQL.
  • Metadata API(Partial implementation)
  • Login with OAuth

I've developed only required features. Probably this library will not implement all of Salesforce features.

SalesforceExplorer is a reference implementation of this library.


Sample

Login

    SalesforceClient client = new SalesforceClient(new File("partner.wsdl"));
    UserInfo userInfo = client.login(SALESFORCE_USERNAME, SALESFORCE_PASSWORD, SALESFORCE_SECURITY_TOKEN);
    System.out.println(userInfo.getUsername() + ", " + userInfo.getDisplayName());

Query

    QueryResult result = client.query("SELECT ID, NAME FROM Account");
    for (SObject obj : result.getRecords()) {
        System.out.println(obj.getId() + ", " + obj.getString("Name"));
    }

Retrieving metadata

    SObjectDef objectDef = client.describeSObject("Account");
    if (objectDef != null) {
        for (FieldDef field : objectDef.getFieldList()) {
            System.out.println(field.getName() + ", " + field.getLabel() + ", " + field.getFieldType());
        }
    }

Creating object

    SObject parent = client.newObject("parent__c");
    parent.set("ExId__c", "xxxx");
    
    List list = new ArrayList();
    for (int i=0; i<10; i++) {
        SObject child = client.newObject("child__c");
        child.setName("test_" + (i+1));
        child.set("parent__r", parent);
    }
    List resultList = client.create(list);
    for (SaveResult result : resultList) {
        System.out.println(result.isCreated() + ", " + result.getId());
    }

Insert and delete statement

    String insert = "insert into test__c (name, int__c, date__c) values(?, ?, ?)";
    for (int i=0; i<10; i++) {
        DmlResult ret = client.executeUpdate(insert, "test_" + (i+1), i+1, new Date());
        System.out.println(ret.getSuccessCoount() == 1 ? "OK" : "NG");
    }
    DmlResult ret2 = client.executeUpdate("delete from test__c where int__c <= ?", 5);
    System.out.println("DeleteCount = " + ret2.getSuccessCount());//5

Bulk upsert from select statement.

    java.sql.Connection con;
    String sql = "SELECT Id as ExId__c, Name as Text__c, ParentId as \"parent__r.ExId__c FROM table1";
    SQLSyncRequest request = new SQLSyncRequest(con, sql, "test__c");
    request.setExternalIdFieldName("ExId__c");
    client.syncSQL(request);

More description and samples are published on Heroku.(Japanese only)


Latest release

Download - 1.2.1

Maven

    <repositories>
        <repository>
            <id>jp.co.flect</id>
            <name>FLECT maven repository</name>
            <url>http://flect.github.io/maven-repo/</url>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>jp.co.flect</groupId>
            <artifactId>flectSalesforce</artifactId>
            <version>1.2.1</version>
        </dependency>
    </dependencies>

License

MIT

商用利用を公式サポートする有償版のご用意があります。

詳細は info@flect.co.jp にお問い合わせください。