How To Setup And Test Outbound Message In Salesforce?

This Tutorial Explains How to Setup And Test Outbound Messages from Salesforce to the External System Through PutsReq or Request Bin:

Workflow is nothing but a way to automate certain business processes. Workflow rule can be created and based on the criteria that are set in the rule the following actions can be performed:

  • New outbound message can be sent.
  • A new task can be created.
  • New Email Alert can be sent.
  • New Field Update can be done.

Salesforce Outbound message

How To Create A Workflow Rule?

Set up => Enter App in quick find box => Click Workflow Rules under Workflow & Approvals.

Searching for Workflow rule

Click the ‘New Rule’ button to create a new workflow rule.

New workflow rule

Select the Object and click ‘Next’.

worklfow object selection

Enter Rule name, select the Evaluation criteria and Rule Entry criteria. Click Save & Next button.

Enter Rule Name

Edit Rule Tutorial page appears. Click Save.

edit rule tutorial

Workflow created.

Workflow Created

workflow actions

What Is Outbound Message? How Does It Work?

The outbound message is one of the actions in the Workflow Rule. It sends the information to an endpoint that is specified and is designated as an external system or service. Outbound messages are also associated with approval processes or entitlement processes.

Outbound messages generally allow specifying the changes to fields within salesforce and will cause messages to be sent to the designated external servers along with field values. Whenever there is an update in the fields within Salesforce then outbound messages will be sent to the external systems with updated values.

Diagrammatic Representation Of Outbound Message:

Outbound message

If the workflow is triggered, then the outbound message will be sent to the endpoint URL that is specified. The message will contain the fields that are specified when the outbound message is created.

When the web service endpoint URL receives the message, it will take the information from the message and it will be processed. SOAP message notification can comprise up to 100 notifications.

The Outbound SOAP message is sent to an external service in a separate WSDL. From the Salesforce user session/interface, WSDL is created and available. This happens once the workflow rule is associated with an outbound message.

WSDL consists of instructions on how the endpoint service can be reached and what data is sent.

Endpoint URL For Outbound Messages Using PutsReq

What Is PutsReq?

PutsReq is used to record the HTTP requests as well as fake responses. Outbound messages can be checked with PutsReq. We have seen the configuration of Workflow rule.

Once the Workflow criteria are met, the Outbound message will be triggered. The format of the message sent can be tested. We can test what payload is sent to the external system and test the Outbound message. PutsReq allows us to create a service that has an Outbound message.

PutsReq displays request headers, body and it sends acknowledgment receipt to Salesforce.

How To Create PutsReq URL For Outbound?

PutsReq can be created and we can use that as the endpoint URL in the Salesforce Outbound message.

Following steps must be followed in order to create PutsReq:

Go to PutsReq and then click the ‘Create a PutsReq’ button.

Create Putsreq

PutsReq URL is generated.

PutsReq URL

Add the SOAP Response for the acknowledgment in the Response Builder. Click the ‘Update’ button.

Add SOAP Response

SOAP response will get updated. This response is used to make an acknowledgment to Salesforce with respect to the successful delivery of the Outbound message that we send.

Now note down the PutsReq URL that can be used as the End point URL for an outbound message.

Following is the Code for Response Builder that sends the response to the corresponding Outbound message to the Salesforce after successfully receiving the Outbound message.

// Build a response
var msg;
msg = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">';
msg+='<soapenv:Body>';
msg+='<notificationsResponse xmlns="http://soap.sforce.com/2005/09/outbound">';
msg+='<Ack>true</Ack>';
msg+='</notificationsResponse>';
msg+='</soapenv:Body>';
msg+='</soapenv:Envelope>';
response.body = msg;

How To Set Up Outbound Message In Salesforce?

With the help of Outbound messaging, a message can be sent to the specified endpoint URL. Outbound messages sent to the endpoint URL will contain the fields that are specified while creating the Outbound message.

The message will be received by the endpoint URL and it will take the information from the message to process. Outbound messaging WSDL must be examined. We must configure the Outbound messages in Salesforce before any data is received by the publisher.

Go to Setup => Search as Outbound in Quick find box => Click Outbound messages.

Outbound message search

Click the ‘New Outbound Message’ button.

Creating New Outbound

Select the Object for which Outbound must be sent and click the ‘Next’ button.

Object selection in outbound message

Give a suitable name for the Outbound message.

New the Outbound message

Enter the Endpoint URL generated in the PutsReq. PutsReq URL must be generated before you create the outbound message.

Endpoint URL of putsreq

Select the fields that must be sent in the outbound and click ‘Save’.

Selected fields for Outbound

Outbound message details after saving is shown below.

Outbound message details

Search ‘Outbound’ in the quick find box and click on Outbound messages. Given below is the newly created Outbound message using Putsreq URL

newly created Outbound message using Putsreq

Create A New Workflow Rule For Outbound Message

Go to Setup and search Workflow in Quick find box and click on Workflow Rules link.

Workflow Rules Link

Click the New Rule button.

New workflow rule

Select the Case object as it is mentioned in Outbound already.

Object selection in workflow

Click Next and give the workflow name.

Workflow rule name

Enter the workflow criteria and Save. The evaluation criteria are given as “Created and any time its edited to subsequently meet criteria”.

Note: So, whenever a case record is created or anytime when it is edited and meets the workflow criteria then an outbound message will be sent.

Workflow evaluation criteria

Click on Existing action under Immediate workflow actions as we have already created the Case Outbound message.

Existing action selection

Select Outbound Message.

select outbound message

Add the outbound message to the selected action.

Add Outbound message

Add Selected actions and save.

Select Existing Actions

Outbound added to the workflow.

outbound added to workflow

Finally, Case workflow must be activated.

Activated Case workflow

Settings To Configure Outbound Message

  • Object: Select the object for which the outbound must be sent.
  • Name: Specifies the name of the outbound message.
  • Unique Name: Unique name refers to the API name. The unique name field will contain alphanumeric characters and underscores. This must be unique.
  • Description: Description helps the users to know what the outbound message will do.
  • Endpoint URL: The message will be sent to the recipient based on the endpoint URL. SOAP message will be sent by Salesforce to this endpoint.
  • Object fields: The fields that are to be sent in the outbound message will be specified by selecting the fields in the object.

Considerations For Outbound Message

The following points must be considered while creating an Outbound message:

  • A SOAP message can contain up to 100 notifications. Each notification will contain an ID that uniquely identifies a record. If there are any information changes in the record after sending the notification, only then the updated information will be sent.
  • Messages will be queued until messages are sent.
  • If the endpoint is not specified or unavailable, then the messages will stay in queue until sent or will be available in the queue until 24 hours.
  • After 24 hours, the messages will be dropped from the queue.
  • If we retry to send the message, then the intervals between retries will increase exponentially up to 2 hours.
  • Messages that are retried will be independent of their order queue. So, the messages will be delivered out of order.
  • The source object might get changed after the notification is sent but before it is delivered. The endpoint will receive only the latest data and do not receive any intermediate changes.

Outbound Message Notifications

Outbound message notifications can be requested for up to 5 users in order to receive notification that lists all the outbound messages that are failed for at least 24 hours. The notification will be sent every 24 hours till the user cancels the request.

Failed Outbound messages will be deleted from the related list after seven days or we can delete it by ourselves before they are removed.

How To Track The Delivery Status Of Outbound Message?

In order to track the Outbound message status, go to Setup and enter Outbound in Quick find box.

Tracking outbound

Click on Outbound messages.

All outbound page

Click the button ‘View Message delivery Status’.

‘View Message delivery Status’

The delivery status can be checked as shown below.

Delivery status page

Next items for delivery: This represents those messages that are awaiting delivery.

Oldest failure in the queue: This represents the messages that are not deleted. The messages have not been delivered. The messages are not 24 hours old.

Testing Outbound Message Using PutsReq

We have already created the Puts req URL in order to check if the Outbound is sent or not. Workflow rule must be created and associated with the corresponding Outbound message. The earlier steps and screenshots can be referred for this.

Follow the below steps to validate the Outbound Message:

#1) At first, check if any Outbound is received in PutsReq. If no Outbound is received then ‘0’ will be displayed under Requests.

PutsReq before Req is received

Note: If requests must be cleared then click the ‘Clear History’ button.

Clear History

#2) Then Create a new Case record that satisfies the criteria for the Outbound message. Criteria for the Outbound message is: Priority must be High, and Origin should be Phone.

Create a new Case

#3) Click Save. Case record is created.

Another case record created

#4) Go to the PutsReq window and check if Outbound is received or not. 1 outbound is received as it displays ‘1’ under Requests.

Outbound received

#5) Fields mentioned in the Outbound message are sent.

Finally, the outbound message is sent from Salesforce to an external system using PutsReq. It is used to record the fake responses from Salesforce.

Outbound message sent

#6) Response: Acknowledgment is sent to Salesforce after receiving the Outbound message.

Response of outbound

Considerations

  1. If the PutsReq URL is not available, then the messages will stay in the queue.
  2. An acknowledgment will be sent to Salesforce in order to avoid sending the same message repetitively.
  3. If the messages are not delivered then it will retry to send it irrespective of their order in the queue.

Benefits

  1. ‘Response’ will be sent to the CRM(Salesforce) once the outbound message is received successfully.
  2. Whatever the update might be, only one response will be sent.
  3. Information can be accessed easily from the Outbound message.

Request Bin

Similar to PutsReq, Request Bin can also be used to validate the Outbound message from Salesforce.

Now let’s see how to check the same Outbound message using Request Bin.

Go to Request Bin. Click Create a Request Bin.

Click Request Bin

The endpoint will be generated.

End Point is generated

Click the Generate Test Events button. Then give this Request bin Endpoint URL in the Outbound message. Create a Case record that satisfies the workflow criteria.

Another new case record

Save the record.

Save Record

Go to the Request bin and check if Outbound is received. The response is received in a Structured manner.

Response is received in Structured manner

Fields are received in the Outbound.

Fields received in Request bin

We can also view it as Raw format. Click the ‘Raw’ tab to view.

Raw response in Request bin

Difference Between PutsReq And Request Bin

The Request bin will not send the acknowledgment back to the Salesforce on receiving the Outbound message successfully. Thus, Salesforce will keep resending the outbound message for the next 24 hours.

When we refresh the Request Bin browser window, the same message will be displayed again and again. In order to prevent Salesforce from resending the same message, the message can be deleted from the Outbound message queue in Salesforce.

We can check the status of the Outbound message in ‘Outbound Messaging Delivery Status’ that was explained already.

Outbound delivery status_Request bin

Whereas PutsReq will send the acknowledgment immediately once outbound is received and the same message will not be resent by Salesforce.

Conclusion

We explored all about Salesforce Outbound Message Testing in this tutorial along with the step by step screenshots. Thus, Outbound messages from Salesforce to the external system can be tested through PutsReq or Request Bin.

Happy Reading!!