Thursday, September 1, 2022

How to Send an Outbound Message Using Flow and What is an Outbound Message ?

 


In salesforce, an outbound message is a specific type of action that transmits data in the form of XML to an external service endpoint (Extensible Markup Language). It used to transmit object field data to your third-party application so it may carry out the required task.

A common use case is to create/update Order records in backend systems like  Order Management System , whenever a new Order gets created or an existing Order gets updated in Salesforce.

Image from the Salesforce SOAP API Developer Guide illustrating the Outbound Message flow:




Four Salesforce capabilities that let us perform automations on record creation/updation are:

  1. Process Builder
  2. Workflow Rules
  3. Salesforce Flow
  4. Apex Trigger

Workflow Rules, Process Builder, and Salesforce Flow are among the first three features that fall under Salesforce's declarative functionality, whereas Apex Trigger needs authoring code. 

We can send an Outbound Message using Workflow Rules or by using Salesforce Flow. But the best option is to adopt Salesforce Flow because Salesforce has previously said that Workflow Rules & Process Builder would be deprecated by 2023.

This blog will show you how to send outbound messages from the Flow.

Before moving in to Salesforce to send an Outbound Message, first we need an endpoint URL. So, for the endpoint URL, we will use a service called that is provided by PipeDream at https://pipedream.com. PipeDream enables us to create public endpoints for receiving and inspecting HTTP requests from any source, as well as easily inspecting the headers, payload, and more.

Steps to create an endpoint URL in Pipe Dream:

1. Go to https://pipedream.com and complete the Signup Process



2. After completing the Signup Process you will land to this page. Click on Sources Tab in the left Panel. After this click the "New Button"
  


3. After clicking the "New Button". Select source as HTTP/WebHook
                  

4. Select  New Request


5. Give the Name for your Service and Click the button "Create Source".


6. After Click the button you will get an endpoint URL. This is the endpoint URL we are using for sending an outbound Message. So Save it.


7. Now Click on Configuration Tab


                                            This page will appear:



8. Replace the Content-Type of the body returned in the HTTP response to application/xml



9. Replace the Response body The body to return in the HTTP response with the following code given below:-
                

<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:out="https://soap.sforce.com/2005/09/outbound">
    <soapenv:Header/>
    <soapenv:Body>
        <out:notificationsResponse>
            <out:Ack>true</out:Ack>
        </out:notificationsResponse>
    </soapenv:Body>
</soapenv:Envelope>


    Steps to create an outbound message in salesforce:

    Remote Site Setting:-
    1. Navigate to Setup.
    2. In the Quick Search Box, type Remote Site Settings.
    3. In Remote Site Settings, select New Remote Site.
    4. Fill in the Remote Site Name field with Your Own Name.
    5. Paste the URL from Pipe Dream into the Remote Site URL field.
    6. Disable Protocol Security should be checked. Otherwise, leave it unchecked  because it is an optional option.
    7. Provide a description (Optional).
    8. Check that the Active Checkbox is selected.
    9. Check that the Active Checkbox is selected.
    10. Click Save.


    Creating an Outbound Message:-
    1. Navigate to Setup again and in the Quick Search Box, type Outbound Message.
    2. In Outbound Message Settings, select New Outbound Message .
    3. Select Object as "Opportunity" and click Next

           4. Give the Name for the Outbound Message. Unique Name will be auto-populated. Give the description if you want. Paste the endpoint URL from the Pipe Dream. Enable the checkboxes for the Protected Component and for Send Session ID and then select the opportunities fields that you want to send. Save it.

    Using Flow to send an Outbound Message:-

    In this example whenever the Opportunity stageName updated to 

    1. From Setup, in the Quick Find box, enter Flows, select Flows, and then click New FlowSelect the flow type as "Record Triggered Flow", then click Next.






    2. Click on Add Element and select Action as an Element and search for  the outbound message that we have created in previous steps. Give the label and then click done.




    3. Activate this flow.

     

    We have done all the steps that were required. now is show time:-

    Our Service is waiting for response from Salesforce:-


    In opportunity set the stage Name as 'Closed Won'. the record trigger flow is trigger and which will send an outbound message to our Service.


    Service received an event from Salesforce:-


    Expand the body-raw  to see the message received from salesforce:



    Useful Links:-

    We hope that you find this blog helpful, if you still have queries, don’t hesitate to contact us at omsfdc91@gmail.com.


    Please do give some suggestions on your behalf in which I should prepare more content.

    1 comment: