[SalesForce] Returning an error to an outbound message

In my app I provide users with a link to use in an Outbound Message which expects certain fields to be sent depending on what they said they would send during the configuration on my side.

On successful processing of the outbound message I return a success body like this:

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

Which works fine. My question is, is it possible to return an error message back to Salesforce so that it shows up in the Outbound Messages monitor?

For example, say the user in my configuration says they are going to send the Case ID, and the Contact ID, but when I receive the outbound message it didn't include the Contact ID. I'd like to return an error to Salesforce like:

    <?xml version="1.0" encoding="UTF-8"?>
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
        <soapenv:Body>
            <notificationsResponse xmlns="http://soap.sforce.com/2005/09/outbound">
                <Ack>Missing required field "Contact ID"</Ack>
           </notificationsResponse>
        </soapenv:Body>
    </soapenv:Envelope>

So that message shows up in the Delivery Status queue and the user can see what they did wrong, fix it, and retry sending.

Is that something that's possible to do?

Best Answer

No, unfortunately there is no direct mechanism to return error messages in the notificationResponse for Outbound Messaging.

<element name="notificationsResponse">
    <complexType>
        <sequence>
            <element name="Ack" type="xsd:boolean" />
        </sequence>
    </complexType>
</element> //This section is the last in the types definition section.

Source - Understanding the Outbound Messaging WSDL

You can only use the Ack boolean in the response to return an ACK or NACK.

Voting for the idea Logging and Notification on Errors in Outbound Messages might help in the long run.


The Notification will have an OutboundMessage Id element along with the sObject that triggered the notification.

As Eric commented, you could use this along with the SessionId and PartnerURL from the notifications to write a record back to Salesforce with the details of the failure. This could be to a field on the record in question, or to a dedicated error handling record.

You could, for instance, make a chatter post on the problem records in Salesforce to indicate what the problem was.

Related Topic