This project demonstrates the interaction between a Heroku app and Salesforce, using Heroku Connect. The app is a single-file Python Flask application.
This project assumes that you have a Salesforce Developer Edition environment and a Heroku account. Once those pre-requisites are met, follow the instructions below.
These instructions will create a Heroku app, deploy this project into the app, and configure the app.
-
Click the
Deploy to Heroku
button below. You will be directed to a Heroku app deployment page. If you'd like to keep these instructions open, right-click on the button and clickOpen Link in New Tab
instead. -
Choose a unique name for your app. If you leave it blank, Heroku will generate a unique name for you.
-
Click the
Deploy app
button at the bottom of the screen. -
Once the build and deployment are complete, click the
View
button at the bottom of the screen.
These instructions will connect the app's Heroku Connect add-on to your desired Salesforce environment.
-
On the welcome page of your app, click the
Connect Salesforce Environment
button. Keep this tab open. -
On the Heroku dashboard page for your app, click the Heroku Connect row in the Add-ons table.
-
Click the
Setup Connection
button in the upper-left corner. -
The
DATABASE_URL
row within the Database Config Vars table should be highlighted. Click the row anyway (Heroku cannot detect that it is auto-selected for some reason). Your app expects the schema to be named "salesforce", so leave that setting alone. -
Click the
Next
button in the upper-right corner. -
The environment should be set to
Production
and the API version should be set to the latest Salesforce version. At the time of this writing, the latest API version is43.0
. Click theAuthorize
button in the upper-right corner. -
Type in the username and password for your Salesforce Developer Edition environment to which you'd like to connect. Click the
Log In
button. -
Once the environment has been authorized, you should be redirected back to Heroku, on your Heroku Connect add-on page. Keep this tab open.
These steps will ensure that your Salesforce environment can receive record changes from the Heroku app. A new field is created that is used by Heroku during the write-to-Salesforce process.
-
Login to your Salesforce environment (most likely, you will use login.salesforce.com).
-
Open the Setup Menu. This is done by clicking the gear in the upper-right corner, then clicking the
Setup
dropdown. -
Click the "Object Manager" tab.
-
Click the
Contact
link in the Contact row. -
Click the "Fields & Relationships" tab in the sidebar.
-
Click the
New
button in the upper-right corner. -
Select the
Text
radio button. -
Click the
Next
button in the lower-right corner. -
Use the following settings:
- Field Label: External Contact Id
- Length: 32
- Field Name: External_Contact_Id
- Description: This field is used by Heroku Connect to sync changes back to Salesforce. It should never be modified within Salesforce.
- Help Text: This is an internal field. You probably don't want to change this value.
- Required: Leave unchecked
- Unique: Check. Ensure the "Treat ABC and abc as duplicate values (case insensitive") radio button is selected.
- External ID: Check
- Default Value: Leave blank
-
Click the
Next
button in the lower-right corner. -
Click the
Visible
column checkbox at the top of the table twice to select-all profiles, then de-select-all profiles. Select visibility for:- Standard Platform User
- Standard User
- System Administrator
-
Ensure no profiles in the
Read-Only
column are checked. -
Click the
Next
button in the lower-right corner. -
Click the
Add Field
column checkbox at the top of the table to de-select-all layouts. Then, select only the "Contact layout" row. -
Click the
Save
button in the lower-right corner.
These steps will map your Salesforce environment Contact sObject to the Heroku app's PostGreSQL database.
-
Return to the tab with your app's Heroku Connect add-on page. Click the "Mappings" tab.
-
Click the
+Create Mapping
button in the lower-right corner. -
Select the "Contact" row from the table of sObjects.
-
In the "Salesforce -> Database" section, check the
Accelerate Polling
checkbox. -
In the "Database -> Salesorce" section, check the
Write database updates...
checkbox. From that setting's dropdown, selectExternal_Contact_Id__c
as the unique identifier. -
In the "Mapped Fields" section, ensure the following fields are checked (It is OK if additional fields are selected due to Heroku Connect auto-selecting them):
- FirstName
- LastName
- Phone
- Title
-
Click the
Save
button in the upper-right corner. -
After a short time, the Heroku Connect mapping you just created should register a number of mapped fields, SF rows, and DB rows.
-
Return to the tab that has your app and refresh the page. You should now see a table containing contacts from your environment!
-
To view a contact, select their contact row.
-
To edit a contact, change the contact's information and click the
Save
button. You should receive confirmation that the record was saved into the database. -
To verify that the change was synced, login to your Salesforce environment. Click the "Contacts" tab and locate the contact that you changed. Verify that the information was updated.