Dynamic Approvals in Salesforce Using Visual Workflow
We needed a dynamic approval process for our new HR system (FinancialForce HCM), where the 3 approvers for a consultant job requisition needed to be based on the budget managers for the related department, cost center, and region. Budget manager is a custom lookup field to user.
I quickly came across this article on developer.force.com and got ready to spin up a SOW to get some developers working on it. The code is needed to lookup a user on a reference object, and populate that user into the record being submitted for approval.
And then i realized that a flow could easily pull an ID from the user lookup on the parent record and dump it to a custom field on the child. However, I would need an apex plugin to kick off the approval process from the flow.
Back to the developers to build an apex plugin…
And then, whilst browsing the great cloud flow posts on salesforce yoda’s website, I stumbled across a set of pre-built plugins from Rajaram, the PM for flow. (July 2014 Update: Rajaram is no longer w/ Salesforce and the GitHub page has been taken down - SalesforceYoda has the source code for the plugins on his site). These plugins deliver so much awesome functionality in flows, including sending emails and triggering an approval process.
So here we are. A cloud flow w/ a pre-built apex plugin. Pretty much a button-click dynamic approval process.
The apex plugin is ridiculously simple to use. Pass the ID of the record to be approved into the plugin, map the response back to your flow, and add a fault path to be safe. One caveat - if a record does not meet the entry criteria for any active processes, the flow will complete successfully - it will not throw an error. So you would need to build the logic for the entry criteria into the flow itself, and use decision elements to display an error message when appropriate.
And note that there is a pilot in Summer14 for submitting for approval from Flows, so the plugin likely wont be needed for long (safe harbor and all). Hopefully the pilot will address the issue when a record does not meet the entry criteria.