Heroku - 22 API REST Introduction

This lesson introduces the third way to integrate Heroku with Salesforce: the native Salesforce REST API. The goal, as always, is to synchronize data between Salesforce and Heroku. Salesforce stores its data in objects: each object is an independent table, with fields you can use to store information and shape business logic. The REST API lets you manipulate every one of these tables from outside Salesforce — typically from a Heroku application. By default you can create, read, update and delete records, just like with any standard RESTful API.

Concrete example — a landing page collecting emails

Imagine a landing page whose goal is to make visitors sign up to a newsletter by entering their email. Salesforce is used to manage all those emails and later send promotions, secondary products, and so on. To feed Salesforce, the landing page (hosted on Heroku) sends a REST request to the Salesforce API every time a user submits their email; the API creates a new row in the Lead (or any other) object with that email. This simple flow shows how easily external apps can write into Salesforce.

Anatomy of the endpoint

The endpoint to perform an action on the Account object looks like this:

https://<instance>.salesforce.com/services/data/v<version>/sobjects/Account
  • Instance — the URL that Salesforce gives you when you sign up to the platform.
  • services/data — tells Salesforce we want to manipulate data.
  • v<version> — the API version you target.
  • sobjects/Account — the object you are acting on. Change the last segment to address another object.

Building these requests by hand is doable, but it is recommended to use a client library that already wraps authentication and error handling. In Node.js, jsforce is the library we will use in the practical part of the course. If you do not use Node, you will find equivalents in nearly every Heroku-supported language: simple-salesforce for Python, the Salesforce Force.com Toolkit for Java, and so on.

Limits to consider

Two limits matter when choosing the REST API approach. First, each request can weigh at most 3 MB, and you cannot interact with more than 2,000 rows in a single call. Second, Salesforce caps the number of API calls per day, with a daily quota that depends on your account type. Before committing to this integration, estimate the number of calls you expect per day and make sure you stay well within your allowance.

When to use it

The REST API is a practical solution for managing Salesforce data, but it is a bit slower than Heroku Connect: each request has to travel from the browser client through your Heroku app to Salesforce. Avoid it for data that changes many times per day, because the request volume can hurt performance and quickly burn through the daily API limit. Conversely, if your data rarely changes — for example configuration data, or any dataset that is not edited several times per day — the REST API is a great choice: you get near-real-time sync between Salesforce and Heroku at a significantly lower cost than Heroku Connect. Overall, the Salesforce REST API is a powerful tool to have when you need to push or pull large amounts of data into or out of Salesforce. See you in the next lesson.