A customer recently came to me with what sounded like a simple requirement. They wanted to send a Salesforce Outbound message when a record was deleted.
This turned out to be slightly trickier than I originally thought so here’s how we solved it. Big thanks to Usman Ali for tackling this problem with me.
- The customer wanted to use standard/declarative tools if possible
- The customer wanted to use Outbound messaging so that the template/fields being transferred were editable (out of the box).
Delete is not one of the actions currently supported by Workflow or Process Builder (to trigger the action) *
Apex Triggers have an AfterDelete function but cannot natively call Outbound Messaging *
Several forums mentioned creating an Apex Class callout that would give all of the same information that the Outbound Message does but the customer wanted easy editing within the User Interface. I’ve linked to some of those posts below.
If you’d like to learn more about Outbound Messaging, please visit this page. (https://help.salesforce.com/articleView?id=workflow_managing_outbound_messages.htm&type=5)
In this instance, we suggested a combination of an Apex Trigger, Process Builder, and the standard Workflow Outbound Message Action to achieve the requirement.
- Create a checkbox field Delete_It__c (Default FALSE)
- The Apex Trigger in after delete monitors for a record being deleted with Delete_it__c = FALSE then clone the deleted record, set Delete_It__c to TRUE and insert it.
- Create a workflow rule which should fire on insert with criteria of Delete_It__c = TRUE
- Create an action to send Outbound message
Flow (To call from Process Builder)
- Create a flow and create a input variable to receive record ID to delete the cloned record created by trigger where Delete_it__c = TRUE.
- Create a Delete Record element in flow and using record ID passed by process builder delete record.
- Create a Process Builder which should fire on insert with criteria of Delete_It__c = TRUE
- Create an action to call flow, then select above-created flow and pass record ID to that flow.
Note : We cannot delete cloned (Delete_it__c = TRUE) record from apex trigger because trigger fires before workflow rules and process builders, and in this case we want to send outbound message first and then delete it, therefore we choose process builder for that purpose to delete record create by apex trigger.
In Salesforce, there are multiple ways of achieving the desired end to end focus. We like to pride ourselves on finding the best fit for our customer’s requirements.
Please contact us today if we can help you.