4

Scenario

  • custom object X that needs several approvals
  • custom object where the approval routings are defined. (so to which approvers does the system need to send the object depending on a stage of the custom object X)
  • several actual approval processes where for each of them, the approvers are set to "manually selected". Each of these approvals also have specific "final approval" and "final rejection" actions
  • each approval process should work in a unanimous approval way, meaning that it's either all approvers that approve or that approval should be rejected

What is OK so far

Since I need to get the approval entities dynamically from my approval routing object, I needed to work with apex to submit the approvals. I quickly noticed that the setNextApproverIds didn't except just multiple user ID's but only one... I still find this über-strange but OK... I found this post which sort of does the trick, at least part of it.

Apex approval process that requires unanimous approval from multiple approvers

The problem

The problem however with this is that working this way, the "final approval" and "final rejection" action would fire immediately as soon as only 1 of the approvers would take action. This because instead of having 1 approval instance with multiple approvers, you just have 1 approval instance per approver...

The question

  1. Is there really no way through apex to do a unanimous approval exactly like it would work through the usual approval processes?
  2. If the answer to 1 is no, how to correctly handle these final approval / rejection actions? This, also knowing that we can have multiple approval processes on the same record.
1

We came across this situation recently and this is how we solved it..

  1. Set the approvers in the process using "Related User" fields. If you leave it as "Manually selected" then you won't be able to submit to multiple approvers from Apex because the method setNextApproverIds() accepts only one ID (as you already know). By using "Related User" fields, you're eliminating the need to call setNextApproverIds() method.

  2. In your code, populate the related users (approvers) on the object before you submit for approval. This implies that you define approver fields (lookups to User) on the object.

This way you have only one approval instance with multiple approvers and your unanimous setting in the process definition will work as expected and so do your final approval/rejection actions. Basically, you're defining everything in the approval process itself (which is how it should be) and in Apex you're just populating user fields and submitting for approval.

Now, one restriction you'll run into- you will need to populate all the approvers (related users) you defined in the approval process. For example, if you defined 3 approvers in the process then you must populate all 3 approvers. If a particular record needs only 1 approver as opposed to 3 defined in the process then it will fail. A workaround for that is to set the same approver for all three!

| improve this answer | |
  • I think that could actually work. Now, one downside of this is that you would be limited to the number of approver fields you configured on your object. I basically could have 1 approver for the first stage and 10 for the last stage. Now I think in most cases, I would think it's workable and they could live with the limit. To be safe, you could then create lets say 10 user lookups and they just have to take into account they can't configure more than 10 per approval or something. – KoenVM Feb 11 '15 at 15:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.