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:
8 %requires SalesforceRestClient
11 "client_id": ENV.SALESFORCE_CONSUMER_KEY,
12 "client_secret": ENV.SALESFORCE_CONSUMER_SECRET,
13 "username": ENV.SALESFORCE_USER,
14 "password": ENV.SALESFORCE_PASS,
17 SalesforceRestClient rest(opts);
18 hash ans = rest.get(
"sobjects");
The composite API can be used to work with multiple objects at once as in the following example:
- Example:
1 list sub create_accounts(list account_list) {
3 list account_numbers = map $1.AccountNumber, account_list;
6 account_list = map $1 + (
"attributes": (
"type":
"Account",
"referenceId": $
10 on_error
printf(
"ERROR info: %N", info);
12 rc.post(
"composite/tree/Account", (
"records": account_list), \info);
14 log(LL_INFO,
"created accounts: %y", account_numbers);
15 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:
8 %requires SalesforceRestClient
12 "client_id": ENV.SALESFORCE_CONSUMER_KEY,
13 "client_secret": ENV.SALESFORCE_CONSUMER_SECRET,
14 "username": ENV.SALESFORCE_USER,
15 "password": ENV.SALESFORCE_PASS,
18 SalesforceRestClient rest(opts);
21 list al = map (
"Id": $1.Id), rc.get(
"query?q=select Id, Name from Account where Name like 'Account %%'").body.records;
23 hash h = rc.bulkJobCreate(BulkJobDelete,
"Account", BulkJobJson).jobInfo;
24 printf(
"created job %y\n", h.id);
26 string data = make_json(al);
28 rc.bulkJobAddBatch(h.id, data, BulkJobJson, \info);
30 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.1
SalesforceRestClient v1.0
- the initial version of the SalesforceRestClient module