How does Heroku Connect bridge Salesforce data with Heroku Postgres databases for enterprise applications?
Answer
Basics: Heroku apps work best with a relational database, while Salesforce data sits behind APIs with call limits. Heroku Connect copies the Salesforce data you choose into Postgres (usually in a schema named salesforce), so a web app, a customer portal or an analytics job reads and writes with SQL instead of calling the Salesforce API. It is part of the Salesforce Platform Services offering that sits beside Heroku, and it is billed by plan according to the number of mapped rows.
How it works:
- Provision the Heroku Connect add-on and attach it to a Heroku Postgres database.
- Authorize it to a Salesforce org with OAuth, using a dedicated integration user.
- Create mappings. Each mapping links one Salesforce object to one Postgres table and lists the fields to copy.
- Heroku Connect creates the tables with columns for each field plus housekeeping columns such as
sfid,id,isdeleted,systemmodstamp,_hc_lastopand_hc_err. - Salesforce to Postgres: Heroku Connect reads changes using the Salesforce APIs, by polling or by accelerated polling that uses push notifications.
- Postgres to Salesforce: triggers log each row change in a trigger log table, and Heroku Connect sends those changes to Salesforce through the API.
Advanced / deep dive: Heroku Connect consumes Salesforce API calls and Bulk API capacity, so very large or chatty mappings need budgeting. Conflicts follow a last-write-wins model, and there is no cross-system transaction. Record ownership and sharing are not replicated, because the integration user's access defines what is copied. Alternatives are Salesforce Connect with OData (data stays in place, with query latency on every read), Pub/Sub API or Change Data Capture (event streaming with no stored copy), and middleware such as MuleSoft. Choose Heroku Connect when the app needs relational joins, high read volume or offline-tolerant access.
Code / config example:
-- Heroku Postgres: insert a contact; Heroku Connect pushes it to Salesforce.
INSERT INTO salesforce.contact (firstname, lastname, email)
VALUES ('Ada', 'Lovelace', 'ada@example.com');
-- Check status: _hc_lastop = 'PENDING' | 'SYNCED' | 'FAILED'
SELECT id, sfid, _hc_lastop, _hc_err FROM salesforce.contact WHERE email = 'ada@example.com';
Hidden gotchas & must-remember points:
- Latency is seconds to minutes depending on the polling mode, not sub-second. Verify current intervals in the Heroku docs.
- Rows inserted from Postgres have no
sfiduntil the sync completes; use an external ID to make later upserts reliable. - Salesforce validation rules, required fields and triggers still run, and failures appear in
_hc_errrather than in your app. - It is not Heroku External Objects. External Objects use Salesforce Connect and do not copy data.
- Deleting a mapping or its data in Postgres does not delete Salesforce data unless the delete is replicated.
- A single integration user determines field-level security for everything that is synced.
Best practice: Map only the objects and fields you need, use external IDs, and monitor the sync status and error columns.