Recipe - XML outbound messaging

This recipe transfers records between two orgs. The first org sends an XML event using an Outbound Message flow. The second org receives the XML event using a webhook flow and returns a SOAP acknowledgement.

Recipe
1st org - send outbound message
2nd org - receive XML webhook
Testing the flows

1st org - send outbound message

Use flow to trigger the message when leads are created:

2nd org - receive XML webhook

In the Streams app Integrations tab, click New Webhook Flow:

# Streamscript to read the SOAP payload
$request = Xml-Decode $Webhook.request

# Records
$Lead = []
foreach ($notification in $request.Envelope.Body.notifications)
{
    $l = New-Lead
    $l.FirstName = $notification.sObject.FirstName
    $l.LastName = $notification.sObject.LastName
    $l.Company = $notification.sObject.Company
    $Lead.add($l)
}

# The variable name must indicate its type
return $Lead

Create the Lead records:

Acknowledge the event using the webhook response:

# Streamscript to send HTTP response
$Webhook.response = `<Envelope
xmlns:out="http://soap.sforce.com/2005/09/outbound"
xmlns="http://schemas.xmlsoap.org/soap/envelope/">
 <Header/>
 <Body>
  <out:notificationsResponse>
   <out:Ack>true</out:Ack>
  </out:notificationsResponse>
 </Body>
</Envelope>`

Click the settings gearwheel to enable the Site Guest User to insert records safely.
In Flow Properties > Advanced > How to Run the Flow: System Context With Sharing.

Testing the flows

Creating a lead in the first org will send the following XML payload:

<Envelope
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
 <notifications xmlns="http://soap.sforce.com/2005/09/outbound">
  <Notification>
   <Id>041000000000001AAA</Id>
   <sObject xsi:type="sf:Lead" xmlns:sf="urn:sobject.enterprise.soap.sforce.com">
    <sf:Id>00Q000000000001AAA</sf:Id>
    <sf:CreatedDate>2023-07-18T12:04:17.000Z</sf:CreatedDate>
    <sf:FirstName>John</sf:FirstName>
    <sf:LastName>Citizen</sf:LastName>
    <sf:Company>ACME</sf:Subject>
   </sObject>
  </Notification>
 </notifications>
</Body>
</Envelope>

You can also test the endpoint manually using Postman. Lead records appear in the second org within a few seconds.

To secure the endpoint, enforce IP restrictions on the site and verify that the session in the payload is valid.