Salesforce Trigger Recording Workflow

I want to listen to changes in my old system whenever there are any changes to the SF object (add / update / delete). So I created an outgoing message and a workflow. But in the workflow, I do not see the ability to run if the object is deleted.

In any case, can I start an outgoing message about deleting a record? I know, I heard that this can be done using a trigger. But I do not want to write vertex code for this.

+4
source share
4 answers

As far as I know, this is impossible to do, the workflow actions are separated from the workflow rule (you can even reuse them), so they probably don’t get the transaction scope, and when they write, they have already disappeared, and all the link inside the action indicates to non-existent data. So the only way I know how to do this is by a trigger.

+5
source

Here is a workaround. However, this will only be the ability to capture deletion done through std. Salesforce user interface.

1.Create a custom excluded check box
2. Reload the Del link using the special VF page, which first updates the record status to "Is Deleted" and deletes the record.
3. Accept the workflow rule using the "Is Deleted" field.

+2
source

Perhaps a compromise architecture would be to write an extremely small and simple delete trigger after the trigger, which simply copies the deleted records to some new user object. This new custom object starts your workflow rule and thus sends the outgoing message you are looking for. The only problem with this is the periodic clearing of user object data, which will increase in size when deleting records from your other object. In other words, your “scratch” object simply needs to be cleaned periodically, which could be done on a night schedule with batch Apex.

Here's a deletion trigger that could do the trick using Opportunity as an example:

trigger AfterDelete on Opportunity (after delete) { List<CustObj__c> co = new List<CustObj__c>(); for(Opportunity o : Trigger.old) { CustObj__c c = new CustObj__c(); c.Name = o.Name; c.Amount__c = o.Amount; c.CloseDate__c = o.CloseDate; c.Description__c = o.Description; // etc. co.add(c); } insert co; } 

This is not ideal, but at least it saves you from having to code your own outgoing messages based on triggers. This can only be done using the @Future annotation, by the way, since callouts directly from triggers are not allowed. Hope this helps.

+1
source

write one email in a trigger delete event. You have it in less than 1 hour.

+1
source

Source: https://habr.com/ru/post/1385538/


All Articles