function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
clouduserclouduser 

Workflow approval process in apex with multiple processes

Hi All,

 

We have 2 approval processes with 15 steps in first process and 5 steps in second process. (total = 20 steps). After completion of the first process, trigger will kick off the second process. It works fine when all steps are approved. It doesnt work when it is rejected in 16th step, it doesnt go back to the 15th step for approval. Any thoughts to resolve this issues?

 

Appreciate your help!

 

regards

 

Peter_sfdcPeter_sfdc
Need more information!

What are your final approval and final rejection settings for your approval? What is the trigger looking for to determine whether or not to launch the second approval.

Fundamentally, the trigger can't be directly triggered by the approval, there must be a field update on the final approval for the record being approved that is being used in the trigger as a condition for execution of the second approval.

Please share code and fill us in with more pertinent details so we can help!

Cheers!
clouduserclouduser

Steps are below:

Process1: Final approval action is field update i.e Process1_Approved__c = true; then apex trigger will be kicked off

 

Apex trigger: 

trigger ClearnaceSubmitForApproval on Clearance__c (after update) {
for (Integer i = 0; i < Trigger.new.size(); i++) {
if (Trigger.old[i].Process1_Approved__c == false && Trigger.new[i].Process1_Approved__c == true ) {
Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
req.setComments('Process 1 is approved. Going to process 2.');
req.setObjectId(Trigger.new[i].Id);
Approval.ProcessResult result = Approval.process(req);
}

}

After process 2 starts..then it goes through respective steps...

Process2 : entry crtieria: Process1_Approved__c

Process2:  final approval action is field update i.e. Final_Approval__c = true

 

let me know if you need any additional details...

I was under the impression that approval process rejection works fine as per the process and steps order...

like approvals from process1 -> process 2

and rejections from process 2 -> process 1

like step1.1 ->..................-->step 1.15 ---> step 2.1 --> .....................--> step 2.5

rejections in reverse order...

Peter_sfdcPeter_sfdc
So you want a rejection in the first step of the second process to make the user step back to the last step of the first process?

If that is the case, then I don't think you'll be able to do that. Each approval process is its own independent entity. When process one is completed, that ship has sailed. There's no way to go back to it. If you are making Apex trigger the second process, there will certainly not be an automatic reversal that steps you back from the second to the first.
clouduserclouduser

thanks for the update. Nice to have these features for implementing the multiple approval processes...