Simple Salesforce Client

Simple Salesforce Client that allows for CRUD operations on Salesforce objects

License

License

Categories

Categories

CLI User Interface
GroupId

GroupId

com.github.dt209
ArtifactId

ArtifactId

sfdcclient
Last Version

Last Version

0.2
Release Date

Release Date

Type

Type

jar
Description

Description

Simple Salesforce Client
Simple Salesforce Client that allows for CRUD operations on Salesforce objects
Project URL

Project URL

https://github.com/DT209/sfdcclient/

Download sfdcclient

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.dt209/sfdcclient/ -->
<dependency>
    <groupId>com.github.dt209</groupId>
    <artifactId>sfdcclient</artifactId>
    <version>0.2</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.dt209/sfdcclient/
implementation 'com.github.dt209:sfdcclient:0.2'
// https://jarcasting.com/artifacts/com.github.dt209/sfdcclient/
implementation ("com.github.dt209:sfdcclient:0.2")
'com.github.dt209:sfdcclient:jar:0.2'
<dependency org="com.github.dt209" name="sfdcclient" rev="0.2">
  <artifact name="sfdcclient" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.dt209', module='sfdcclient', version='0.2')
)
libraryDependencies += "com.github.dt209" % "sfdcclient" % "0.2"
[com.github.dt209/sfdcclient "0.2"]

Dependencies

compile (3)

Group / Artifact Type Version
com.squareup.okhttp3 : okhttp jar 3.10.0
org.apache.commons : commons-lang3 jar 3.7
org.apache.commons : commons-text jar 1.3

test (1)

Group / Artifact Type Version
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

Simple Salesforce Client (sfdcclient)

This is the simplest possible SFDC client, it does proper authentication and allows for basic CRUD operations.

Building

Build:

./gradlew build -x test

Assemble all artifacts:

./gradlew assemble

List all gradle tasks available:

./gradlew tasks

Including in your project:

Please see Maven Central

Testing

Before running the tests you must have a valid Salesforce API Enabled username/account. This account must have privelages to read/write/update/delete Salesforce Account objects

  • Set an environment variable of u with Salesforce username
  • Set an environment variable of p with Salesforce password for the user above (case-sensitive)
  • Set an environment variable of t with Security token for the user above(case-sensitive)
./gradlew test

Architectural Decisions

Adhere to the KISS principle as much as possible. Choosing to use simple highly maintainable code rather than being fancy Reduce number of dependencies

Examples:

// Create client (Note: that the constants are just defaults, feel free
// to find the best suited SOAP Path for your Org similarly if you decide
// to use domains and want to use a different host.  The default
// HOSTS are login.salesforce.coma and test.salesforce.com,
// the default SOAP_PATH is (or was at some point) /services/Soap/u/42.0)
SfdcClient sfdcClient = new SfdcClient(
        SfdcClient.SANDBOX_HOST,
        SfdcClient.SOAP_PATH,
        salesForceUsername,
        salesForcePassword,
        salesForceSecurityToken
    );

// Get list of Account objects (any SFDC object will work):
List<Map<String, String>> queryResult = sfdcClient.query("SELECT Id, Name FROM Account");

// Select specific fields, useful for more generic code, where clause is required here. ID should be escaped!
Collection<String> fields = new ArrayList<>();
fields.add("Id");
fields.add("Name");
List<Map<String, String>> accounts = sfdcClient.selectFields("Account", fields, "Id = '" + id + "'");

// Change name of Account (any SFDC object will work)
Map<String, Object> sfdcObject = new HashMap<>();
sfdcObject.put("id", id); // Required!
sfdcObject.put("Name", newName);
sfdcClient.update("Account", sfdcObject);

// Create Account object (any SFDC object will work):
Map<String,Object> sfdcObject = new HashMap<>();
sfdcObject.put("Name", accountName);
String id = sfdcClient.upsert("id", "Account", sfdcObject);

// Delete SFDC Object by ID:
sfdcClient.delete(id);

Logging

Uses Java's internal logging framework as to minimize dependencies.

Logger logger = Logger.getLogger(sfdcClient.getClass().getName());
logger.addHandler(new ConsoleHandler());
logger.setLevel(Level.ALL);

Depenedencies

Currently this project only has three dependencies (okhttp, commons-lang3 makes use of ClassUtils, commons-text makes use of StringEscapeUtils), and their version isn't super important so feel free to replace them as long as they basically funciton the same there should be no issues.

Releases

Bump up the release number then issue:

./gradlew clean uploadArchives closeAndReleaseRepository

Background on releases

Versions

Version
0.2
0.1