Using the Salesforce REST API with Heroku
Last updated April 20, 2022
Table of Contents
The Salesforce platform provides a comprehensive REST API that can be called from a Heroku application. The API provides OAuth 2.0 or session ID authentication, and allows you to query Object Metadata, create or modify records, execute SOQL/SOSL queries, and interact with approval processes.
When to Use
Use the REST API in scenarios where you need more than just a data integration. You must be prepared to build a reasonably low-level integration using the REST API, but after you do, the API does let you perform a considerable number of actions on Salesforce.
Calling the API
Community libraries, such as nforce or JSForce for Node.js, can provide convenience wrappers for invoking the API. Such libraries are available for most languages. After authenticating the client, you can perform a SOQL query and update an object like this:
var q = 'SELECT Id, Name, CreatedDate, BillingCity FROM Account WHERE Name = "Spiffy Cleaners" LIMIT 1';
org.query({ query: q }, function(err, resp){
if(!err && resp.records) {
var acc = resp.records[0];
acc.set('Name', 'Really Spiffy Cleaners');
acc.set('Industry', 'Cleaners');
org.update({ sobject: acc, oauth: oauth }, function(err, resp){
if(!err) console.log('It worked!');
});
}
});
Limits & Considerations
See the Implementation Considerations of the API documentation, which outline concurrent API request limits, API calls per license type, API calls per day, and so on.
Security and Heroku/Salesforce integrations shows how to secure this integration.
Learn More
- The REST API documentation.
- A Reference Guide to the various end points.
- Integration libraries for Node.js, Ruby