Skip to main content

I have a flow approval orchestration that fires when a case gets created. This will create one to many approver steps. I want to withdraw or cancel all the approval work items when the case is closed. Is this possible?  

 

I have tried publishing a 

flow orchestration event

 from an apex trigger when a case closes. But I have been getting mixed results using this method. The events published successfully when you close a case as a system admin, but other profiles, no matter what permissions I grant, don't seem to be able to publish them, even though they're published from a trigger which runs in a system context. When the events publish successfully the approval work item sometimes updates to Approved and sometimes stays as Assigned which is also not ideal. I would prefer the status of the Approval Work Item to be updated as Withdrawn.  

 

Should I be adding some sort of condition to the flow approval itself that can check if the case goes into a closed status? I also tried updating Approval Work Items directly via Flow or Apex but its a Read Only system object. 

 

Example of a Flow Orchestration Event that I publish. The property values are populated correctly regardless of the profile.

{OrchestrationInstanceId=0jEDl000000KysXMAS, StepInstanceId=0jLDl000000Kz1kMAC, StepStatus=Completed}

 

Error received when publishing Flow Orchestration Event as non sys admin:  

Orchestrator Event: Event payload value is invalid: StepInstanceId 

 

@* Salesforce Developers * @Salesforce Flow Automation

 

 

#Flow

2 Antworten
  1. 30. Jan., 22:02

    The best and easiest solution was to add a stage condition that checks if the Case record is closed to every Stage that includes an Approval Step (see screenshot at bottom of this comment for an example).

     

    When you change the Stage condition to "When the specified requirements are met, the stage is marked Completed" a message displays that says: "

    When a requirement resource references a record variable or $Record and the underlying record changes, it can trigger the evaluation of stage and step conditions."

     So anytime the Case.IsClosed field becomes true the stage will be considered complete. Since I am using an autolaunched Flow Approval I query the case record using a Stage and Background Step before any approval steps. 

      

    All approval work items related to the case that is closed get a status of Withdrawn. 

      

    Also, if you are looking for a way to customize the ability to Recall or Cancel an approval submission you no longer need to rely on creating an LWC and writing Apex. You can use the 

    Recall Approval Submission Flow Action or Cancel Approval Submission Flow Action. These actions are only available in a Screen Flow, meaning a user must actually manually click a button to recall or cancel. So if you need to recall or cancel programmatically without user interaction then I would recommend using the Advanced Approvals Standard Invocable Actions via the REST API. But note that Canceling an approval submission requires the Approval Admin user permission which isn't something you would want non system admin users to have. Recalling an approval submission works if the user is the submitter of the approval submission or the user has the Approval Admin user permission. If there are multiple approval work items related to a single record when any one approval submission record is cancelled or recalled all the other approval work items will also be cancelled or recalled.

     

    Screenshot of my stage condition checking if the case is closed:The best and easiest solution was to add a stage condition that checks if the Case record is closed to every Stage that includes an Approval Step (see screenshot at bottom of this comment for an examp

0/9000