Lot of times, customer facing websites depend on a relational database as there primary datastore. These applications which depend on Salesforce for back-office uses, it is important to bridge these two systems to give a great experience to customers.
For example, we have an external application which contain customer-related data like coupon code which is edited by customers, but sometimes a customer care representative has to view and edit this data from within salesforce. So we need ways to integrate salesforce application with external data. One of the ways to integrate is to use Heroku External objects and Salesforce connect.
In Heroku external objects, we have a new read/write feature which makes it very easy to integrate salesforce and external data stored in Heroku Postgres.
You are already familiar with Heroku connect and also its ability to synchronize salesforce data with Heroku Postgres database. Heroku connect is useful when primary system of record is salesforce database and external system needs to interact with salesforce data.
But if Heroku Postgres is the main datastore and salesforce needs to access this external data,we can use Heroku External objects- included as part of Heroku Connect add on.
Heroku External objects create standard Odata endpoints for Heroku Postgres database which can be used by Salesforce connect. In case of salesforce connect, the data integration is done on demand. There are pros and cons of using on-demand and synchronization methods.
Pros of using Heroku connect synchronization:
- Low latency rate to access external data datastore
Cons of using Heroku connect:
- You might not have the latest data because data is not read on demand.
But in case of using Heroku external objects, the data is always up-to-date because there is no local copy of the data and data is always read on demand.The external objects are very similar to salesforce object in there look and feel even though these external objects reside in external system.
Let’s do some practice:
In this section, we will use a simple Java application which stores “bars” information in Heroku Postgres database. After we are done deploying our application on Heroku and setting up Heroku External objects, we will use salesforce connect to expose this data inside of salesforce.
Step 1: Create a free Heroku Account and sign up for free salesforce developer account.
Step 2: Deploy our Java application on Heroku.
Now you have a java application deployed on Heroku which uses Heroku Postgres as its datastore.
Step 3: You can access the code here
Step 4: Provision Heroku connect for your application
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 you will also receive a username and password in your inbox.
Step 6: Create a new External Data source in Salesforce using the OData 4 URL from external objects. Enable “Writable External Objects” and use “Named Principal” and “Password Authentication” with the credentials emailed to you in your inbox.
Step 7: Click “Validate and Sync” button to retrieve the metadata from the OData service and also create/sync the “publicSbars” External object. After you have created the “publicSbar” external object, edit and remove the “id” custom field.
Step 8: Create a new custom object tab for “publicSbars” external object. Once the tab is created, click on the tab and you will be able to view the records and will be able to create new records.
Great Job!! you have deployed an app on Heroku that shares its data with Salesforce database using Heroku external object. This is a basic example, but it shows us how to bring external data into salesforce with read and write access.
I also have create a course on Salesforce Integration with Heroku in which I have covered various integration methods like salesforce connect, heroku connect and webservice callouts in detail.
You can check the complete course https://mytutorialrack.com/salesforce-heroku-integration/