How to catch Salesforce Outbound Messages with NodeJS?
- January 3, 2020
- 4 minutes
- Outbound messaging is part of the workflow rule functionality in Salesforce. Workflow rules watch for specific kinds of field changes and trigger automatic Salesforce actions, such as sending email alerts, creating task records, or sending an outbound message.
When building applications that are integrated with Salesforce (Salesforce Integration), one of the choices you have to make is how you get data out of Salesforce and into your app. You can use one of the many ETL tools on the market, you can poll for changed records, use the Force.com Streaming API, use Apex HTTP Callouts from Salesforce or Outbound Messages.
However, with that said, Outbound Messages are quite magical. You hook them up as an action to your Workflow Rule so that whenever a record is, for example, created or updated in some manner, the platform will fire off some record data to the endpoint specified in the Outbound Message.
Now we need to set up the Workflow and Outbound Message that will send the data to your NodeJS application. You’ll want to change the Workflow to meet your criteria as this one fires every time a Contact record is created or updated and the mobile phone is not blank.
The actual Outbound Message below defines the endpoint (you’ll notice I’m running it locally using ngrok), the fields from the record to include in the message (the record Id and MobilePhone) and finally “Send Session ID” is checked. You’ll probably want to include the Session ID so that you can grab it from the message and use it to quickly make calls back into Salesforce using something like nforce.
If you want to test the application locally you can use something like ngrok to securely expose your local web server. Salesforce (thankfully) requires that all endpoints use HTTPS so ngrok comes in handy.
Now if you modify a Contact record in Salesforce, you should see the following in your terminal if everything is configured correctly:
There’s also a mocha test you can run to ensure that the XML is being parsed correctly.
There you have it… a simple NodeJS app to get you started using Outbound Messages from Salesforce.