Monday, October 23, 2017

Dynamic Approval Process

Approval processes route a record to one or more approvers, specifying the steps necessary for a record to be approved, and who must approve it at each step.
In a typical approval process (what you're calling a "static" approval process), the approvers at each step are explicitly specified in each step approval process. You have a little flexibility -- for example, you can have the submitter choose the approver manually, or you can automatically assign it to the submitter's or record owner's manager, or to a queue -- but there's a limited pool of people who can be approvers.
Dynamic approval routing allows you to specify the approvers for each record using User lookup fields on the record requiring approval. The fields are populated using Apex, using data from a special custom object (the "approval matrix") that contains all the information needed to route the record. The approval process then uses the values in the lookup field, rather than the limited pool of users available in the so-called static process. This provides more flexibility: you could route to different people based on region or some other criteria related to the record, rather than having to write multiple static approval processes in order to perform the same functionality.
The steps for dynamic approval routing are:
  1. Create lookup fields on the object being approved.
  2. Create a custom object that will be used as an approval matrix.
  3. Populate the approval matrix.
  4. Create Apex code to fill in the lookup fields on the record, from the approval matrix.
  5. Create or update an approval process to utilize the new lookup fields.
For example: suppose you have a position object and there are 3 levels of approvers. You need to route the record to different approvers based on the department and pay grade. You would:
  1. Add custom lookup fields (to User) on the Position object, called Approver 1, Approver 2, and Approver 3.
  2. Create an approval matrix object that stores all the fields used in routing: pay grade, department, and lookup fields to the User object for each approver.
  3. Create the approval matrix records. For position, one might route records with the department of Engineering to high-level Engineering managers as approvers, whereas the department of Sales would have high-level Sales managers as the approvers.
  4. Use an Apex trigger to populate the lookup fields on the Position record when the record is created, based on the values in the approval matrix.
  5. On the approval process, in the approval steps, set the Assigned Approver to the appropriate lookup field on the record (Approver 1, Approver 2, and Approver 3).
As you can see this is more complex and requires Apex, but it can be powerful if you have complex and changing routing requirements. One other point to note is that while users require Customize Application in order to customize an approval process, the approval matrix object is just a regular custom object with the same CRUD and sharing possibilities as any other object, so you could allow non-admins to change the approvers.
Additional documentation/examples that may be helpful: - Approval Process Overview (Salesforce Help & Training) - Using a Matrix-Based Dynamic Approval Process (Force.com Cookbook) - Force.com Dynamic Approval Routing (Salesforce Developers)
Using a Matrix-Based Dynamic Approval Process

Problem

You want to be able to create a single criteria-based approval process to route opportunity discount approval requests to designated approvers, based on the requester's region and the opportunity's account type.

Solution

The Dynamic Approval Routing application, available for free on AppExchange, provides a sample solution that automates an opportunity discount approval process based on region and account type, and routes opportunities through three required levels of approval. The Dynamic Approval Routing application comes packaged with the necessary custom object, validation rule, Apex class, and Apex triggers and tests. The package also comes with documentation on how to customize the application to fit your needs.
To take advantage of dynamic approvals, do the following:
  1. Go to AppExchange and install the Dynamic Approval Routing application.
    For Developer Edition organizations, or any organizations with fewer than three users, select the Ignore Apex test failures checkbox before installing the package. Otherwise, the Apex test fails and the installation does not succeed.
  2. Once installation is complete, click All Tabs, then click Customize My Tabs. Add the Approval Routing Rules tab to the Selected Tabs list.
  3. Customize the following fields' picklist values to match your organization.
    • Owner Region—Custom picklist field on the User object to model the opportunity owner’s region. Set the region for all opportunity owners.
    • Account Type—Custom picklist field on the Opportunity object to model the account type associated with the opportunity. Set the account type for all opportunities.
    You may have to enable the Owner Region and Account Type fields in the Page Layouts for Users and Opportunities, respectively.
  4. Create an Approval Routing Rule for each combination of region and account type.
    1. Select the Account Type and Owner Region for the rule. The Routing Key, a composite key based on the Account Type and Owner Region fields, is created automatically.
    2. For each rule, select approvers for Level1, Level2, and Level3, the custom user lookup fields used to model the levels of authorization. Approvers for all opportunities are assigned according to the submitter's region and the opportunity's type.
  5. Create the approval process for opportunity discounts.
    1. Click Setup | Create | Workflow & Approvals | Approval Processes.
    2. From the Manage Approval Processes For drop-down list, select the object type for this approval process. For this example, select Opportunity.
    3. Click Create New Approval Process and select Use Standard Setup Wizard.
    4. Enter the Process Name (Opportunity Discount Approval) and Description for your new approval process, then click Next.
    5. From the Use this approval process if the following drop-down list, select criteria are met.
    6. Define the rule to fire when Closed equals False.
    7. Click Next.
    8. Leave the Next Automated Approver Determined By set at None, but select the Administrators OR the currently assigned approver can edit records during the approval process option, then click Next.
    9. Leave the Approval Assignment Email Template blank, then click Next.
    10. Select the fields you want to display on the approval page, click the Display approval history information... option, then click Next.
    11. By default, only the record owner—Opportunity Owner, in this example—is listed under Allowed Submitters. Leave this setting.
    12. Click Save.
      The approval process described here is a generic one. You can create any approval process you want to use the Approval Routing Rules you defined in the Dynamic Approval Routing custom object.
  6. Create the three approval steps to correspond to the Level1, Level2, and Level3 approver fields defined in the Approval Routing Rule.
    1. From the Approval Process Detail page, click New Approval Step.
    2. Name the steps Level 1 Approval, Level 2 Approval, Level 3 Approval.
    3. For the step criteria, select All records should enter this step.
    4. Select Automatically assign to approver(s) and choose Related User.
    5. Find and select Level1, Level2, and Level3 for your three steps, respectively.
    6. Click Save.
Once you become more familiar with how these routing rules work, you can design data-driven approval routing for all approval processes involving multiple routing criteria.

No comments:

Post a Comment

Lightning Inter-Component Communication Patterns

Lightning Inter-Component Communication Patterns If you’re comfortable with how a Lightning Component works and want to build producti...