Loading

Evaluate trigger from approval process

Publiseringsdato: Oct 13, 2022
Beskrivelse
It's not possible to invoke an Apex trigger as a result of starting or completing an approval process. As described in the resolution of this article, you can however, update data (a checkbox) as part of an approval process that can cause a trigger to fire.

The following apex trigger will not work when executed after the record gets approved through Approval Process. 
trigger CreateRecord on Case (after insert) {
 
        for (Case c : Trigger.new) {

            // Define parameters to be used in calling Apex Class
            String objectType ='Case';  
            String objectId = c.id;
            String projectKey = 'SFDC'; 
            String issueType = '1';     
            // Calls the actual callout to create another record.
            SFDCSampleWebserviceCalloutCreate.createRecord(PARAM1, PARAM2, PARAM3);
        }
    }

Løsning

The trigger is not automatically invoked upon the record approval unless there is a field updated during the approval step. To address this, create a checkbox field that should be marked 'trueonce record is approved.

Steps could be as follows:

  • Create a checkbox field to update when its Approved
  • Update this checkbox to true in Approval actions.
  • Compare in trigger and have this in 'IF' Condition whether 'Check_ Box == True'  

Sample Code: 

trigger CreateRecord on Case (after insert) {

        for (Case c : Trigger.new) {
            if (Check_ Box__c = true) {
            // Define parameters to be used in calling Apex Class
            String objectType ='Case';  
            String objectId = c.id;
            String projectKey = 'SFDC'; 
            String issueType = '1';     
            // Calls the actual callout to create another record.
            SFDCSampleWebserviceCalloutCreate.createRecord(PARAM1, PARAM2, PARAM3);
        }
    }

Disclaimer: The code or idea provided in this article is just a sample. This is not officially supported by Salesforce. In future, if the code breaks, you should not rely on support teams to provide a working solution. Such requests will be out of scope.  

 
Knowledge-artikkelnummer

000383878

 
Laster
Salesforce Help | Article