DEV Community

Raja Saha
Raja Saha

Posted on • Updated on

What is Outbound Messages in Salesforce?

Outbound messages are used to send messages to external web services or system application using SOAP API. When a trigger event occurs, a message is sent to a fixed endpoint URL in XML format. This is performed to achieve a specific task as a requirement. The great thing about outbound messages is, it doesn't require Apex coding.

The image simply illustrates how Outbound Messages work…

Image description

  • First user logs in to the system and a user session starts with that login.
  • User create some records or do some changes in records which triggers workflows.
  • Triggered workflow prepares the outbound message and sends it via SOAP API call in the form of XML format.
  • Now web service endpoint is a listener waiting to receive the message.
  • It receives the message process some tasks as per requirement.
  • If everything goes perfect, then external web service sends a success acknowledgment back to Salesforce using SOAP API in XML format.

What are the ways one can send Outbound Messages from Salesforce?

  • Flows.
  • Workflow Rules.
  • Approval Processes.

Note: To proceed further discussion, we have two prerequisites to complete.

Prerequisite 1:

To configure an endpoint URL let's create a listener source. Among many platforms, PipeDream has the ability to work as a listener.

  1. Log in to https://pipedream.com
  2. To create a Source Click on Source > New.
  3. Select HTTP/Webhook as a source type.
  4. Select New Requests.
  5. Change the response content type to: application/xml
  6. Change the response body with the following code.
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope 
   xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
   xmlns:out="http://soap.sforce.com/2005/09/outbound">
   <soapenv:Header />
   <soapenv:Body>
      <out:notificationsResponse>
         <out:Ack>true</out:Ack>
      </out:notificationsResponse>
   </soapenv:Body>
</soapenv:Envelope>
Enter fullscreen mode Exit fullscreen mode

7.Provide an appropriate Name.
8.The final screen should look like the below image. Click Create Source.
Image description
9.Now open the source and copy the endpoint URL. We will need this later.
Image description
10.Notice that on the left-hand side it's waiting for the event.

Prerequisite 2:

Before using the URL in the endpoint of outbound message make that URL Trustable by adding that URL In Remote Site Settings.
Please follow the below step to add the URL in Remote Site Settings.

  1. Go To Setup.
  2. Type Remote Site Settings in the Quick Search Box.
  3. Click on New Remote Site in Remote Site Settings.
  4. Give Your Own Custom Site Name in the Remote Site Name field.
  5. Paste The URL in the Remote Site URL field.
  6. Make Sure Active Checkbox is checked.
  7. Click on Save.

Steps to send Outbound Messages:

For this tutorial purpose let’s proceed with Salesforce Flows as we know Workflows are going to be deprecated in Salesforce 2023 release.

To illustrate this mechanism let’s consider a scenario that a developer wants to send an outbound message to the external system when an Opportunity Stage is Closed Lost.

Steps to Create Outbound Message in Salesforce:

  1. From Setup, enter Outbound Messages in the Quick Find box, then select Outbound Messages.
  2. Click New Outbound Message.
  3. Choose the opportunity object.
  4. Enter a name and endpoint URL for the recipient of the message. Salesforce sends a SOAP message to this endpoint.
  5. Select Send Session ID if you want a sessionId to be included in the outbound message.
  6. Select the fields you want be included in the outbound message and click Add. The final window will look like this.

Image description

7.Click Save and review the outbound message detail page.

Now as outbound Message configuration is all set let’s create a Flow to see the outbound message working.

  1. From Setup open Flows.
  2. Click on New Flow.
  3. Select Record-Triggered Flow and click create.
  4. On configuration page select Opportunity as an object. Select Trigger the flow when A record is created or updated.
  5. In condition requirement select All Conditions Are Met (AND).
  • Field: StageName
  • Operator: Equals
  • Value: Closed Lost

6.Select Optimize the Flow for: Actions and Related Records and click done. The final screen looks like this…

Image description
7.Now drag a new Action element into canvas.
8.Select the Opportunity Outbound Message as an option.
9.Provide Label & API Name. Click done. The final screen looks like this…

Image description
10.Now connect from Start to Action.

Image description
11.Now save the flow. Provide Flow Name & API Name. Now Active the flow.

Testing the Outbound Messages:

All Configuration is done. Now it’s time for testing.

Now create an Opportunity record with Closed Won as a Stage.

Image description
Now go back to PipeDream and Open Events. Under a particular event open the Raw Body to see the data passed on using XML. With every record created or edited with opportunity closed lost will create a separate event message.

Image description
So, what happened in background is, when a record is saved it invoked a trigger flow that sends an outbound message(XML format) to the endpoint URL.

Tracking Outbound Message Status:

To track the status of an outbound message, from Setup, enter Outbound Messages in the Quick Find box, select Outbound Messages, and then click View Message Delivery Status. You can perform several tasks on this page.

  • View the status of your outbound messages, including the total number of attempted deliveries.
  • View the action that triggered the outbound message by clicking any workflow or approval process action ID.
  • Click Retry to change the Next Attempt date to now. This action causes the message delivery to be immediately retried.
  • Click Del to permanently remove the outbound message from the queue.

Top comments (0)