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
snodskov_secuniasnodskov_secunia 

Building dynamic approval flows in Apex

Hi,

 

I would like to know if anyone has any experience in building an approval process where the approvers are picked by the user before submitting the record for approval?

 

Basically, our use-case is as follows:

 

  1. We want to have a reference to multiple User objects (e.g. multi-select, multiple lookups - just assume this has been handled)
  2. Before submitting a record, the user picks one or several users as approvers
  3. When submitting the record, an approval process should be initiated
  4. Whenever an approver approves a record, it should go on to the next approver selected in the user list in step 1

I'm not sure if we can use the native approval process at all or if we are forced to basically code the whole flow ourselves?

 

Is it even possible to create approval processes in Apex? Can one intercept approval processes build by the native functionality and basically override who the next approver should be based on a set of criteria in the code?

 

I've found, and read, some topics on the boards but none of them seem to cover what we would like to achieve. Basically, we're looking for an extremely flexible solution where the submitter of the record decides the list of approvers.

 

I'm looking forward to some great input you guys.

 

Kind regards,

Søren Nødskov Hansen

JohanLiljegrenJohanLiljegren
Will you need to support an unlimited number of approvers or can you assume there will never be more than, let's say, 10 approvers?
You could create 10 or so user lookup field where you populate, behind the scenes, the approvers that the users picks.
Then set up the approval process to reference these fields.

Does that make sense?