Qore SalesforceRestClient Module Reference  1.3

SalesforceRestClient Introduction

The SalesforceRestClient module provides an API for calling REST services with Salesforce.com.

To use this module, use "%requires SalesforceRestClient" in your code.

All the public symbols in the module are defined in the SalesforceRestClient namespace.

The main classes are:

  • SalesforceRestClient: this class provides the REST client API for communuication with Salesforce.com; it also automates authentication and authorization to the target Connected App
  • SalesforceRestConnection: provides a REST connection object to a Salesforce.com server (based on the ConnectionProvider module)
Example:
#!/usr/bin/env qore
%new-style
%strict-args
%require-types
%enable-all-warnings
%requires SalesforceRestClient
hash opts = (
"client_id": ENV.SALESFORCE_CONSUMER_KEY,
"client_secret": ENV.SALESFORCE_CONSUMER_SECRET,
"username": ENV.SALESFORCE_USER,
"password": ENV.SALESFORCE_PASS,
);
SalesforceRestClient rest(opts);
hash ans = rest.get("sobjects");
printf("%N\n", ans.body);

The composite API can be used to work with multiple objects at once as in the following example:

Example:
list sub create_accounts(list account_list) {
# get list of account numbers for return value
list account_numbers = map $1.AccountNumber, account_list;
# add reference IDs for composite REST call
account_list = map $1 + ("attributes": ("type": "Account", "referenceId": $#.toString())), account_list;
# create accounts
hash info;
on_error printf("ERROR info: %N", info);
# maximum 200 accounts can be created; if any errors occur, an exception is thrown
rc.post("composite/tree/Account", ("records": account_list), \info);
log(LL_INFO, "created accounts: %y", account_numbers);
return account_numbers;
}

Requests can also be made with the Salesforce.com Bulk REST API; the following example shows how a list of accounts can be deleted:

Example:
#!/usr/bin/env qore
%new-style
%strict-args
%require-types
%enable-all-warnings
%requires SalesforceRestClient
%requires json
hash opts = (
"client_id": ENV.SALESFORCE_CONSUMER_KEY,
"client_secret": ENV.SALESFORCE_CONSUMER_SECRET,
"username": ENV.SALESFORCE_USER,
"password": ENV.SALESFORCE_PASS,
);
SalesforceRestClient rest(opts);
# get list of Account IDs to delete with the REST API with an SOQL query
list al = map ("Id": $1.Id), rc.get("query?q=select Id, Name from Account where Name like 'Account %%'").body.records;
# create job with the Bulk REST API
hash h = rc.bulkJobCreate(BulkJobDelete, "Account", BulkJobJson).jobInfo;
printf("created job %y\n", h.id);
# create JSON data
string data = make_json(al);
# add batch to job with the Bulk REST API
rc.bulkJobAddBatch(h.id, data, BulkJobJson, \info);
# close job with the Bulk REST API
rc.bulkJobClose(h.id);
See also
"sfrest" in the bin directory for a user-friendly command-line interface to Salesforce.com REST API functionality and a more detailed example of code using this module.

Release Notes

SalesforceRestClient v1.3

  • all connection clases have unified constructor

SalesforceRestClient v1.2

SalesforceRestClient v1.1.1

SalesforceRestClient v1.1

SalesforceRestClient v1.0

  • the initial version of the SalesforceRestClient module