Back

Explore Courses Blog Tutorials Interview Questions
0 votes
4 views
in Salesforce by (11.9k points)

I have an approval process with three steps, all of which are set to Assigned Approver = Manually Chosen. When the user submits the record for approval, I'd like to have Apex code determine who the three approvers are. However, I don't see a way to hook into the approve request submission.

If I submit the approval with Apex Using Approval.process(), I can set the initial (and only the initial) approver with ProcessSubmitRequest.setNextApproverIds(). This call leads you to believe you can specify multiple approvers since it takes an array of Ids, but the array can only have 1 element, or else runtime a error occurs.

Once I know what the first approver's response is, I can use Apex to submit her response and, again, set the immediately next approver by passing a ProcessWorkitemRequest instance to Approval.process(). An important note here is that the approver must not approve via the standard UI. Instead, they must do something that invokes the Apex code so that we can set who the next approve should be. A trigger on the object under review, or a custom button + VF page could be used to invoke the Apex.

My main question is, how can I make sure that the user does not use the standard approval buttons? They appear in the Approvals related list and on the salesforce home screen. It may be in other places as well. Again, if they use the standard submit and approve buttons, I don't have any way to hook in to set the next approver.

1 Answer

0 votes
by (32.1k points)
edited by

You can solve this by creating custom lookup fields to certain users. So, just in case, you want to route an approval request to the Director and then a VP, you can add DIrector_c and MarketVP_c fields to an object. The idea is that these fields are basically populated in code by climbing the role hierarchy whenever a request is submitted. Your approval process steps can then choose who the assignee would be that is based on the values in these fields.

In order to solve the standard approval button issue, you can just hide it from the homepage layout and build your own VF page which would be included in a custom homepage component. This component will then function as an inbox with links to any record that would be pending with a user's approval. Rest all the user interactions with the approval objects would be handled through other VF pages with their own Approve and Reject buttons. 

Go for this in-depth job-oriented salesforce course online!

Browse Categories

...