How to establish approvers for all steps of the approval process?

I have an approval process with three steps, all of which are set to Assigned Approver = Manually Chosen. When a user applies for approval, I would like the Apex code to determine who the three approvers are. However, I do not see an opportunity to look into the approved application.

If I submit the claim using Apex Using Approval.process() , I can set the initial (and only the initial) ProcessSubmitRequest.setNextApproverIds() using ProcessSubmitRequest.setNextApproverIds() . This call makes you think that you can specify several approvers, since it accepts an array of identifiers, but the array can have only one element, or the error execution time.

Once I know what the first approver response is, I can use Apex to send the response and, again, set the next next ProcessWorkitemRequest passing the ProcessWorkitemRequest instance to Approval.process() . It is important to note that the approver does not have to approve through the standard interface. Instead, they should do something that calls the Apex code so that we can determine who the next should be. A trigger for the object in question or a custom button + VF page can be used to call Apex.

My main question is: how can I make sure that the user is not using the standard approval buttons? They appear in the list of relevant claims and on the Salesforce main screen. It may be in other places. Again, if they use the standard submit and approval buttons, I have no way to connect to install the next approver.

+4
source share
1 answer

We encountered a similar problem some time ago and solved it by creating custom search fields for specific users. For example, if we want to send an approval request to the director, and then to VP, we added the Director__c and MarketVP__c fields to this object. These fields were populated with code, rising to the hierarchy of roles whenever a request was sent. Our steps in the approval process then choose who will be the assignee based on the values ​​in these fields (the first step will be assigned to the Associated User: Director, and the second step will be assigned to the Associated User: Market VP, etc.).

To get around the standard approval button (we had other reasons to hide it), we simply hid it from the home page layouts and built our own VF page and included it in the custom component of the main page. This component functioned as a mailbox with links to any records awaiting user approval. All user interactions with approval objects were processed through other VF pages with their β€œApprove and Reject” buttons. I do not know if the objects that you submit to the approval process can use VF pages, so this may not be feasible for your situation.

A lot of settings for something that is not needed, I know. This may not be the answer you are looking for, but hopefully this is food for thought.

+3
source

Source: https://habr.com/ru/post/1413063/


All Articles