Integrating Relational Data into Salesforce with Heroku External Objects & Heroku Postgres

Often customer-facing web and mobile apps utilize a relational database as the primary datastore.  For applications that rely on Salesforce for back-office uses, there can often be a need to bridge the two systems to provide a seamless experience.  For instance, an external application may contain customer-centric data like a purchase discount code which is primarily edited by customers, but on occasion, a customer service rep may need to view and change this data from within Salesforce.  There are many ways to handle this type of integration, but the easiest is to use both Heroku External Objects and Salesforce Connect.  Thanks to the new read/write feature of Heroku External Objects, it only takes a few steps create a two-way integration between Salesforce and external relational data stored in Heroku Postgres.  This makes using Salesforce to view and edit external data stored in Heroku Postgres a straightforward task.

Architecture

You might be familiar with Heroku Connect and its ability to synchronize Salesforce data with a Heroku Postgres database.  This is a great feature when the primary system of record for the data is Salesforce and an external system also needs to interact with the data.  However, if Heroku Postgres is the primary system of record, but the data needs to be accessible in Salesforce, you can use Heroku External Objects — included as part of the Heroku Connect Addon.

Heroku External Objects create standard OData endpoints for Heroku Postgres databases which can then be consumed by Salesforce Connect.  With Salesforce Connect the data integration is done entirely on-demand — no synchronization needed. When considering on-demand and synchronization methods of integration, there are tradeoffs to consider.  With Heroku Connect synchronization, your external apps have very low latency access to the external datastore but may not have the latest data.  However, Heroku External Objects are always up-to-date since there isn’t a local copy of the data, only an on-demand read or write back to the primary data source (Heroku Postgres).

The External Objects that Salesforce Connect exposes in Salesforce look and feel like other Salesforce objects even though they reside in an external system.  These objects can be related to other objects within Salesforce and can provide many of the typical features in Salesforce like search and an out-of-the-box user interface.

Check out a Demo

Get Started

Below you will use a sample Spring Java application which stores “bars” in Heroku Postgres.  After deploying the application and setting up Heroku External Objects you will set up Salesforce Connect to then expose that data inside of Salesforce.  You can get started with Heroku External Objects using free developer environments on Salesforce and Heroku.  Follow these steps:

Step 1) If you haven’t done so already, sign up for a free Heroku account, and a free Salesforce Developer Org.

Step 2) Deploy the Java-based Spring Boot Bars app on Heroku:

You will now have a simple Java web application that uses Heroku Postgres as its datastore.  Try out your simple app at: https://YOUR_APP_NAME.herokuapp.com

Step 3) Add some “bars” to the database via the simple web UI.

Check out the full code for the app at https://github.com/jamesward/springbootbars

Step 4) Add Heroku Connect to the app on Heroku

Step 5) In the Heroku Connect dashboard, setup External Objects for the “bar” table to create OData endpoints.  Copy the OData 4 endpoint URL and check your email for a username and password — you’ll use these in the next step.

Step 6) Create a new External Data Source in Salesforce using the OData 4 URL from Heroku External Objects. Make sure you enable “Writable External Objects” and use “Named Principal” and “Password Authentication” with the credentials emailed to you in the previous step.

Step 7) Use the “Validate & Sync” button to fetch the metadata from the OData service and then sync / create the “public$bars” External Object.  Once the “public$bar” External Object is created, edit it and remove the “id” custom field as this is not necessary.  You can also edit the “name” custom field and set “Is Name Field” to true / selected.

Step 8) Create a new Custom Object Tab in Salesforce which points to the “public$bars” External Object.  You can now visit the tab in Salesforce and view all the records as well as create new ones.  If you visit your app on Heroku, you should also see any new records there as well.

Congrats!  You’ve just created an app on Heroku that shares its data with Salesforce via Heroku External Objects.  This is just a basic sample but shows the simplicity of bringing external data into Salesforce, with read and write access.  With this architecture, you can easily provide back-office access to any relational data in a Heroku Postgres database!

Further Learning

Check out the Heroku External Object docs for more details.

Published
November 15, 2016

Leave your comments...

Integrating Relational Data into Salesforce with Heroku External Objects & Heroku Postgres