Last week’s announcement of Heroku Connect Demo Edition prompted me to take Heroku Connect for a test drive. I had a simple use case in mind: monitor Twitter for tweets from contacts in my org which mention specific hashtags, and show them in Salesforce. It took me just a couple of hours to build a polished integration from scratch – here’s the story. On the Salesforce side, I added a couple of custom fields; Twitter Handle on Contact, and Hashtag on Campaign. These custom fields would allow me to subscribe to a stream of relevant tweets. Twitter has a Streaming API that would give me just what I was looking for, but it’s not a good match for Force.com – I would need an app that ran continuously, listening for notifications from Twitter, rather than Apex code that runs from a database trigger or user interaction. Node.js on Heroku, on the other hand, is a great setup for event-driven apps, and a few seconds searching turned up a Node module for Twitter. It took just a few minutes to write a simple Node app that would stream tweets matching a given hashtag to the terminal. The next step was to read hashtags and Twitter handles from Salesforce

Heroku Connect

I fired up a Heroku app via the Heroku Connect Demo Edition button, and quickly added mappings for Contact and Campaign. In a few seconds, I could see my Salesforce data synchronized into Postgres.

I modified my app to use the Postgres Node module to read Contacts and Campaigns, building a filter for the Twitter Streaming API call, and logging matching tweets to the console. A quick test confirmed that all was working. Now the question was, how to get the tweets into Salesforce. I considered creating a Postgres table and using Heroku External Objects with Lightning Connect, but I realized there was a much simpler route: create a Tweet custom object in Salesforce with lookups to Contact and Campaign and a text field for the tweet content, and let Heroku Connect do the heavy lifting.

Since Heroku Connect provides full, bidirectional synchronization, I could map the Tweet custom object to a Postgres table and simply insert records from my Node app. Heroku Connect took care of synchronizing the data back into Salesforce, and soon I could see tweets in their own list view, and on related lists for both Contact and Campaign.

Grab the source code from GitHub and watch the video to see how it all fits together:

Try it out yourself, today!

It’s easy to get started with Heroku Connect Demo Edition. If you have a Heroku account and Salesforce Developer Edition, all you need to do is click the Heroku Button below. In a couple of minutes you’ll be synchronizing your Salesforce data into Postgres on Heroku, ready for your killer application.

Deploy to Heroku button

Get the latest Salesforce Developer blog posts and podcast episodes via Slack or RSS.

Add to Slack Subscribe to RSS