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…
- 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.
- Log in to https://pipedream.com
- To create a Source Click on Source > New.
- Select HTTP/Webhook as a source type.
- Select New Requests.
- Change the response content type to: application/xml
- 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>
7.Provide an appropriate Name.
8.The final screen should look like the below image. Click Create Source.
9.Now open the source and copy the endpoint URL. We will need this later.
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.
- Go To Setup.
- Type Remote Site Settings in the Quick Search Box.
- Click on New Remote Site in Remote Site Settings.
- Give Your Own Custom Site Name in the Remote Site Name field.
- Paste The URL in the Remote Site URL field.
- Make Sure Active Checkbox is checked.
- 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:
- From Setup, enter Outbound Messages in the Quick Find box, then select Outbound Messages.
- Click New Outbound Message.
- Choose the opportunity object.
- Enter a name and endpoint URL for the recipient of the message. Salesforce sends a SOAP message to this endpoint.
- Select Send Session ID if you want a sessionId to be included in the outbound message.
- Select the fields you want be included in the outbound message and click Add. The final window will look like this.
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.
- From Setup open Flows.
- Click on New Flow.
- Select Record-Triggered Flow and click create.
- On configuration page select Opportunity as an object. Select Trigger the flow when A record is created or updated.
- 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…
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…
10.Now connect from Start to Action.
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.
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.
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)