Allow Sales Users to see Advanced Approvals Preview Screen without Navigating Back to Quote
Related References:
- Solution partially sourced from Daniel Hoechst Gist
- Salesforce documentation that has some of the only specs I’ve found
- Advanced Approvals List View from Milo Massimo
- Idea to allow for customization of the Advanced Approvals Preview Page
Scenario
Sales users, in an org with Advanced Approvals, would like to see what Approvals will be required based on different changes they make to a deal. However, they don’t want to have to go into and out of the QLE to check the ‘Preview Approval’ action. Instead it would be much preferred to be able to launch that Preview Approval via a Custom Action on the QLE itself. One caveat here is that they will need to ‘Quick Save’ any changes they make so that the correct approvals are determined by the page. Since we cannot force the Quick Save prior to using the page, we need to hide the buttons from the VF page, so cannot use the standard page itself.
How do we allow Approval Preview, but not Submission, from the Quote Line Editor without going back and forth to the Quote?
Solution – Credit
Daniel Hoechst has a Gist that gives a full featured implementation of a custom Advanced Approvals page. I used a stripped down version of this approach to meet the Preview Approval from QLE requirement – in this implementation we want a view-only version without any additional functionality.
Solution – Create VF Page
We will create a very slimmed down version of the standard VF page – removing the buttons for Submit and Close (which won’t work from the QLE). I’m leaving lightningStyleSheets off so that it looks the same as when viewed from the Quote itself. We will use the approvalPreview Visualforce component, and pass it the approvals to display using the controller.
<apex:page standardController="SBQQ__Quote__c" extensions="PreviewApprovalsCtrl"
title="Preview Approvals" lightningStylesheets="false">
<style type="text/css">
textarea{
height: 80px;
width:80%;
}
</style>
<apex:outputPanel id="messages">
<apex:pageMessages/>
</apex:outputPanel>
<apex:pageBlock title="Approval Preview">
<sbaa:approvalPreview approvals="{!approvals}"/>
</apex:pageBlock>
</apex:page>
Solution – Create Controller
For the controller, we’ll use the SBAA ApprovalAPI to generate the list of approvals to provide to the Visualforce component. I haven’t found a lot of great documentation here, aside from the article included in references pertaining to enabling approvals from mobile. So very thankful to the aforementioned Gist.
public with sharing class PreviewApprovalsCtrl {
private SBQQ__Quote__c sbQuote;
ApexPages.StandardController qtController;
public PreviewApprovalsCtrl(ApexPages.StandardController stdController) {
this.qtController = stdController;
this.sbQuote = (SBQQ__Quote__c)stdController.getRecord();
}
public SBAA__Approval__c[] approvals {
get {
if (approvals == null) {
approvals = SBAA.ApprovalAPI.preview(sbQuote.Id, SBAA__Approval__c.Quote__c);
}
return approvals;
}
set;
}
}
Solution – Create Custom Action
Navigate to Custom Action and create New. Fill in the record like the below. Make sure to add ‘Approval Preview’ value to the Label field on Custom Action object, and form the the URL like ‘/apex/c__PreviewApprovals?Id={!SBQQ__Quote__c.Id}’ (make sure to match your VF page name). Add whatever Custom Action Conditions you may want to govern when this button should show and make sure to use URL Target of Popup.
Solution – Important Note
I strongly suggest removing the ‘Submit for Approval’ and ‘Cancel/Return to Quote’ buttons from the VF Page. This is because if you allow Submission, without first forcing Save, then you’re going to trigger an Approval process based on the version of the Quote prior to Save. This would then need to be recalled.
Test it Out
Let’s open a Quote that meets at least one Approval requirement. Use the ‘Approval Preview’ button, and verify that you can see the appropriate Approval. Click the ‘X’ to close the window. Success!
Wrapping Up
Thanks for reading, and let me know how your Sales users like this functionality.