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:
- Example:
%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");
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) {
list account_numbers = map $1.AccountNumber, account_list;
account_list = map $1 + ("attributes": ("type": "Account", "referenceId": $
hash info;
on_error
printf(
"ERROR info: %N", info);
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:
%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);
list al = map ("Id": $1.Id), rc.get("query?q=select Id, Name from Account where Name like 'Account %%'").body.records;
hash h = rc.bulkJobCreate(BulkJobDelete, "Account", BulkJobJson).jobInfo;
printf(
"created job %y\n", h.id);
string data = make_json(al);
rc.bulkJobAddBatch(h.id, data, BulkJobJson, \info);
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