Salesforce CPQ – Product Search Executor

The Background

In the prior two posts on Guided Selling, and Product Configuration Initializer, we reviewed some alternative approaches to configuration using Salesforce CPQ.  In this post we’ll extend again on the Guided Selling approach by adding a Product Search Executor.  Product Search Executor is a plugin that allows us to override the standard Guided Selling search and add additional query filters to the Product Search/Filter logic.  That said, there is a gap in the documentation that makes it pretty confusing to start.

Scenario Review

We will continue with our example of configuring a Gaming Laptop using Guided Selling.  In this example, we’ll add an additional filter to ensure the latest version of the laptop is returned.  This will provide some backup in case of gaps in master data maintenance, and will allow us to make sure that the Product Configuration Initializer can function properly.  If we were to have multiple gaming laptops returned this would allow old laptops to be selected, as well as invalidate our applied logic if the Product Options were different.  This example happens to be very similar to the example in the developer documents.

Additional Product Setup

To demonstrate the concept, we’ll clone the ‘Gaming Laptop’ and create a ‘Gaming Laptop Old’.  Also add a Product Family selection option of ‘Legacy’ and set this for Gaming Laptop Old. Don’t forget to also add a Pricebook Entry so that the laptop will show up in selection. 

Create Product Search Executor

Now we will create the Product Search Executor according to the developer documentation.  There will be a controller for the logic and a VF page to call the logic and apply the additional filter to omit where Product Family is ‘Legacy’. Importantly, as we are extending Guided Selling, we have to grab the parameters from the Guided Selling selections to use in the query. This part is not in the documentation, and if you don’t do it then the search will just override any guided selling inputs. In the example below, I’ve gathered the Purpose__c and Mobility__c inputs from the VF page to ensure that these inputs are considered in the custom Executor query.

Create and save the Class:

public class TestProductSearchController {
    public Product2[] products {get; set;}
    public String error {get; set;}

    public TestProductSearchController() {
  
        String purpose = ApexPages.currentPage().getParameters()?.get('Purpose__c');
        String mobility = ApexPages.currentPage().getParameters()?.get('Mobility__c');
        products = [SELECT Id FROM Product2 WHERE Purpose__c =:purpose AND Mobility__c =:mobility 
                    AND Family != 'Legacy' LIMIT 100];
    } 
}

And the Visualforce page:

<apex:page controller="TestProductSearchController" contentType="text/xml" showHeader="false" sidebar="false">
    <products error="{!error}">
    <apex:repeat var="product" value="{!products}">
        <product id="{!product.Id}"/>
    </apex:repeat>
    </products>
</apex:page>

Update Quote Process with the Executor Reference

As we did for the Product Configuration Initializer, we must add the Product Search Executor to our desired Quote Process.  This is done in the Product Search Executor field (naturally), again with the c__ prefix.

Trying It Out

First, let’s test without the Executor enabled in our Quote Process to see the usual result. I’ve highlighted the line that the Executor will omit when it is enabled.

Now we will enable the Product Search Executor, enter the Guided selling as Mobile and Gaming, and see that the Product Family of ‘Legacy’ is now filtered out. Success!

Product Search Executor is an interesting extension option with which to add additional filters to Guided Selling queries. Keep in mind though that it totally overrides the standard behavior, so you need to properly account for all Guided Selling inputs! Thanks for reading!

2 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *