suggest(quote, fieldValuesMap)

Overrides the user suggestion input. Salesforce CPQ calls this method only when isSuggestCustom returns TRUE.

Signature 

global List<PricebookEntry> suggest(SObject quote, Map<String,Object> fieldValuesMap)

Parameters 

quote

Type: SObject

The current quote.

fieldValuesMap

Type: Map<String,Object>

A map of the search criteria. The map key is a Product2 API name and the value is the desired search value. Contains only keys for non-null values.

Return Value 

Type: List<PricebookEntry>

Example 

1/** 
2     * When Using Guided Selling in CUSTOM mode, Over-Ride entire search
3     * Product2 Fields in the Search Results Field Set should be Set.
4     */
5    global List<PricebookEntry> suggest(SObject quote, Map<String, Object> inputValuesMap) {
6        System.debug('METHOD CALLED: suggest');
7        //GET ALL POSSIBLE FIELDS FROM THE SEARCH RESULTS FIELD SET
8        List<Schema.FieldSetMember> searchResultFieldSetFields = SObjectType.Product2.fieldSets.SBQQ__SearchResults.getFields();
9
10        //BUILD THE SELECT STRING
11        String selectClause = 'SELECT ';
12
13        for (Schema.FieldSetMember field : searchResultFieldSetFields) {
14            selectClause += 'Product2.' + field.getFieldPath() + ', ';
15        }
16        selectClause += 'Id, UnitPrice, Pricebook2Id, Product2Id, Product2.Id';
17
18        //BUILD THE WHERE CLAUSE
19        String whereClause = '';
20
21        whereClause += 'Pricebook2Id = \'' + quote.get('SBQQ__Pricebook__c') + '\'';
22
23        //BUILD THE QUERY
24        String query = selectClause + ' FROM PricebookEntry WHERE ' + whereClause;
25
26        //DO THE QUERY
27        List<PricebookEntry> pbes = new List<PricebookEntry>();
28        pbes = Database.query(query);
29
30        return pbes;
31    }
32}