Qore SalesforceRestClient Module Reference 2.0.1
Loading...
Searching...
No Matches

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<auto> 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<string> sub create_accounts(list account_list) {
# get list of account numbers for return value
list<string> 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<auto> 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<auto> 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<hash<auto>> 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<auto> 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 v2.0.1

  • fixed OAuth2 refresh token handling

SalesforceRestClient v2.0

  • updated to use the generic OAuth2 support in the RestClient class

SalesforceRestClient v1.5.1

  • added support for username and password connection options for better security handling

SalesforceRestClient v1.5

  • implemented support for a data provider scheme cache and rich option information for connections (issue 4025)

SalesforceRestClient v1.4

  • removed the SalesforceRestConnection::getConstructorInfo() and SalesforceRestConnection::getConstructorInfoImpl() methods (issue 3696)
  • added support for the data provider API

SalesforceRestClient v1.3

  • all connection clases have unified constructor

SalesforceRestClient v1.2

  • added the SalesforceRestConnection::getConstructorInfo() method to allow connections to be created dynamically, potentially in another process from a network call (removed in SalesforceRestClient 1.4) (issue 2628)

SalesforceRestClient v1.1.1

SalesforceRestClient v1.1

SalesforceRestClient v1.0

  • the initial version of the SalesforceRestClient module