You are here:
Enable an Object for Advanced Approvals
Advanced approvals are enabled for opportunities by default. However, most sales reps also use advanced approvals on quotes or other objects. Configure an object to work with Advanced Approvals. (Salesforce CPQ Managed Package)
Required Editions
| Available in: Salesforce CPQ Summer ‘16 and later with Advanced Approvals 3.1 and later |
Before you begin, make sure that you have Read access to all the fields on the Approval object. If you have a licensed custom object as a lookup field on the Approval object, enable Read access on the licensed custom object by using a permission set license.
This example shows how to enable approvals for the Quote object. You can enable approvals on any Salesforce CPQ object if the object has a field with the API name Name. If you’re enabling advanced approvals on the Case object, use the CaseNumber field.
To enable approvals on other Salesforce CPQ objects, follow these steps but replace instances of Quote with the name of the object.
-
Create a field on the Approval object with these values.
Make the field visible, but not on the page layout.
- Data Type: Lookup
- Field Name: Quote
- Related to: Quote
-
Create a picklist field on the Quote object with these values.
- Name: Approval Status
- API Name: ApprovalStatus__c
- Values:
- Pending
- Approved
- Rejected
- Recalled
-
Create a date field on the Quote object.
This field stores the submitted date for the approval.
- Name: Submitted Date
- API Name: SubmittedDate__c
-
Create
a user lookup field on the Quote object.
This field stores the user record for the user who submitted the quote for approval.
- Name: Submitted User
- API Name: SubmittedUser__c
- If you’re enabling advanced approvals on quotes, make sure that the quote validation rule Invalid_First_Segment_term_end_Date is inactive.
- From Setup, in the Quick Find box, enter Apex Classes, and then select Apex Classes.
-
Create an Apex class titled QuoteExtController and add this code.
Important The Salesforce CPQ package comes with a QuoteExtController for the SBQQ namespace. However, for this step, you’re creating a different QuoteExtController class. Because it’s a custom class, it doesn’t have a namespace and can run at the same time as SBQQ__QuoteExtController.public with sharing class QuoteExtController { private Id quoteId; public QuoteExtController(ApexPages.StandardController stdController) { quoteId = stdController.getId(); } public PageReference onSubmit() { if (quoteId != null) { SBAA.ApprovalAPI.submit(quoteId, SBAA__Approval__c.Quote__c); } return new PageReference('/' + quoteId); } public PageReference onRecall() { if (quoteId != null) { SBAA.ApprovalAPI.recall(quoteId, SBAA__Approval__c.Quote__c); } return new PageReference('/' + quoteId); } } -
Create another Apex class with the title QuoteExtControllerTests as a test
class for the class that you made. In the class body of QuoteExtControllerTests,
add this code.
@isTest private class QuoteExtControllerTests { testMethod static void testSubmit() { SBQQ__Quote__c quote = new SBQQ__Quote__c(); insert quote; Test.startTest(); QuoteExtController con = new QuoteExtController(new ApexPages.StandardController(quote)); con.onSubmit(); quote = [SELECT ApprovalStatus__c FROM SBQQ__Quote__c WHERE Id = :quote.Id LIMIT 1]; Test.stopTest(); System.assertEquals('Approved', quote.ApprovalStatus__c); } testMethod static void testRecall() { SBQQ__Quote__c quote = new SBQQ__Quote__c(); insert quote; Test.startTest(); QuoteExtController con = new QuoteExtController(new ApexPages.StandardController(quote)); con.onRecall(); quote = [SELECT ApprovalStatus__c FROM SBQQ__Quote__c WHERE Id = :quote.Id LIMIT 1]; Test.stopTest(); System.assertEquals('Recalled', quote.ApprovalStatus__c); } }

