Guide to Outbound Messaging – How to View the Message

Author: Bruce Tollefson Published: March 11, 2021; Modified: May 9, 2022
connected_dots

Outbound messaging is a configurable workflow-driven method to send messages from Salesforce to an external endpoint. The message is driven by and can only be triggered through a workflow-rule. Outbound messages are SOAP-based messages that contain notifications(up to 100 per message) in the message. Each message can hold multiple notifications which are singular events that occurred. This mechanism has been around for a very long time and is a quick way to create an event-based integration without having to write any code.

In this article, we will explore outbound messaging how to create a message, and more importantly how to view the message to be able to gain a better understanding of the ins and outs. We will create an external endpoint to view the message and test some of the out-of-box functionality.

During this example, we will be creating an outbound message that is triggered by an opportunity being closed won. Once closed we will be sending the message to an external endpoint where we can examine the message. We will be using an integration platform called pipedream. If you would like to follow along and test for yourself you will need to create a free account with pipedream. If you don’t want to create an account you can skip the setup.

Setting up the Pipedream Endpoint

In pipedream click on Workflows –> New –> HTTP API this will create an endpoint we will use later on.

Next click the ‘+’ then Run Node.js Code

Add the the following code, this will be used to log the message and return a successful response to Salesforce:

console.log(event.headers); let decode = steps.trigger.raw_event.body_b64; let buff = new Buffer.from(decode, 'base64'); let text = buff.toString('ascii'); console.log(text); var msg; msg = ''; msg += ''; msg += ''; msg += 'true'; msg += ''; msg += ''; msg += ''; //append ?pipedream_response=1 to the end of the URL to use $respond when making a request $respond({ status: 200, body: msg} )

Setting Up Salesforce Opportunity Outbound Message

Now that we have pipedream all setup we will work on setting up Salesforce to send an outbound message to the endpoint once the opportunity is closed won. In Salesforce go to Setup –> Outbound Messages –> New Outbound Messages pick Opportunity in the Object dropdown.

After selecting the object and clicking next you will be able to add the URL endpoint you would like the message to go to. Along with the endpoint you can select attributes in the notification such as fields from the opportunity and if you would like to add a session ID. When selecting fields from the outbound message you will not be able to add related attributes such as an AccountNumber from the Account however adding the session Id will allow the integration to log into Salesforce and be able to query any additional objects needed. The session will be based on the ‘User to send as’ selection so you will need to make sure the user has the necessary permissions.

After creating the outbound message it is time to create the workflow rule.

Create Workflow Rule

To create the workflow rule in Setup time in ‘Workflow’ click ‘Workflow Rules’ then select the object ‘Opportunity’ and click next. Once selecting the opportunity object you are able to add the criteria Stage equals ‘Closed Won’ and click next. Now you are able to select the outbound message. Click on ‘Add Workflow Action’ select ‘Existing Action’ then ‘Outbound Message’ and the newly created ‘Opportunity Message’. Then click next and Activate.

Now you are ready to test the outbound message and see what it looks like.

View Outbound Message

Create an opportunity with the stage of ‘Closed Won’. A message should be sent from Salesforce to your pipedream endpoint and the message logged and captured in pipedream. By clicking on the message you will be able to view the header information along with the body in the console. From here you can take a look at the message and notification structure. Note there can be multiple(up to 100) notifications in one message.

Outbound Message Retries

One of the great things about outbound messaging is the automatic retry. Salesforce will try to deliver the message for 24 hours. Earlier at the beginning of the pipedream code, we created a response back to Salesforce. Salesforce uses this response in order to know that the external system received the message. For us to test retries we need to remove that response.

We are going to comment out the following, deploy the change, and then create another closed won opportunity.

console.log(event.headers); let decode = steps.trigger.raw_event.body_b64; let buff = new Buffer.from(decode, 'base64'); let text = buff.toString('ascii'); console.log(text); var msg; msg = ''; msg += ''; msg += ''; msg += 'true'; msg += ''; msg += ''; msg += ''; //append ?pipedream_response=1 to the end of the URL to use $respond when making a request /*$respond({ status: 200, body: msg} )*/

After creating a closed won opportunity and saving it go to Setup –> Outbound Messages (Under Monitor) here you will see the outbound messages that are in queue to retry. You can see when the automatic retry will occur. You can also manually retry the message.

In pipedream, you will see the messages being sent and received however since we removed the notification response Salesforce will continue to try sending until the message an acknowledgement is sent or up to 24 hours.

Add failures to failed outbound message related list

Outbound messages will try to deliver the message for 24 hours. After 24 hours Salesforce will not try to deliver the message again. However, you can contact salesforce to activate ‘Add failures to failed outbound message related list‘ when added this is a feature that will be added as a selection checkbox on the outbound message. This will also add the ‘Failed Messages list’ on the monitoring page where unsuccessful outbound messages will show after 24 hours. These messages can then be manually fired to send the message to the external system for up to 7 days. Only messages that are checked with the ‘Add failures to failed outbound message related list’ will be added to the related list. Note: Any change to the record will be reflected in the message notification instead of the values on the record that were there when the message was first triggered.

Security

The endpoint for the external system will need to be publicly accessed, without any additional security measures the endpoint will be vulnerable. To help from attackers pretending to be you here are several ways to add security to the endpoint.

  1. Only accept requests from the trusted Salesforce IP ranges
  2. Only accept requests with your Org Id
  3. Add a certificate to the request and validate the certificate up on request. Go to Setup –> Certificate and Key Management –> API Client Certificate

Leave a Reply

Your email address will not be published. Required fields are marked *