search(quote, fieldValuesMap)

Overrides the entire user search input. Salesforce CPQ calls this method only when isSearchCustom returns TRUE.

Signature 

global List<PricebookEntry> search(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 

This example builds and returns a list of price book entries.

1global List<PricebookEntry> search(SObject quote, Map<String,Object> fieldValuesMap){
2  // Get all possible filter fields from the search filter field set
3  List<Schema.FieldSetMember> searchFilterFieldSetFields = SObjectType.Product2.FieldSets.SBQQ__SearchFilters.getFields();
4  // Get all possible fields from the search result field set
5  List<Schema.FieldSetMember> searchResultFieldSetFields = SObjectType.Product2.FieldSets.SBQQ__SearchResults.getFields();
6  // Build the Select string
7  String selectClause = 'SELECT ';
8  for(Schema.FieldSetMember field : searchResultFieldSetFields) {
9    selectClause += 'Product2.' + field.getFieldPath() + ', ';
10  }
11  selectClause += 'Id, UnitPrice, Pricebook2Id, Product2Id, Product2.Id';
12  // Build the Where clause
13  String whereClause = '';
14  for(Schema.FieldSetMember field : searchFilterFieldSetFields) {
15    if(!fieldValuesMap.containsKey(field.getFieldPath())) {
16      continue;
17    }
18    if(field.getType() == Schema.DisplayType.String || field.getType() == Schema.DisplayType.Picklist) {
19      whereClause += 'Product2.' + field.getFieldPath() + ' LIKE \'%' + fieldValuesMap.get(field.getFieldPath()) + '%\' AND ';
20    }
21  }
22  whereClause += 'Pricebook2Id = \'' + quote.get('SBQQ__Pricebook__c') + '\'';
23  // Build the query
24  String query = selectClause + ' FROM PricebookEntry WHERE ' + whereClause;
25  // Perform the query
26  List<PricebookEntry> pbes = new List<PricebookEntry>();
27  pbes = Database.query(query);
28  return pbes;
29}