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}