CPQ Feature! Recommended Products!

I can not tell you how many times someone has requested to see recommended products after adding a bunch of stuff to the line editor. It’s probably in the top ten functionality requests. I always have to implement some sort of lookup product rule based on their criteria for the recommendations.

Well look no further! There’s actually a hook built in now that you can attach to. It needs: a Custom Object, an APEX class, a Package Setting, and a Custom Action record update. All are below.

Custom Object

APEX Class

global class RecommendedProductsPlugin implements SBQQ.ProductRecommendationPlugin {
    global PricebookEntry[] recommend(SObject quote, List<SObject> quoteLines) {
        // Get the price book Id of the quote
        Id pricebookId = (Id)quote.get('SBQQ__PriceBookId__c');
        
        // Get Ids of all products in the quote
        Id[] productIdsInQuote = new Id[0];
        for (SObject quoteLine : quoteLines) {
            Id productId = (Id)quoteLine.get('SBQQ__Product__c');
            productIdsInQuote.add(productId);
        }
        
        // Query the recommendation custom object records of all products in quote.
        ProductRecommendation__c[] recommendations = [
            SELECT RecommendedProduct2Id__c
            FROM ProductRecommendation__c
            WHERE Product2Id__c IN :productIdsInQuote];
        
        // Get Ids of all recommended products
        Id[] recommendedProductIds = new Id[0];
        for(ProductRecommendation__c recommendation : recommendations) {
            recommendedProductIds.add(recommendation.RecommendedProduct2Id__c);
        }
        
        // Query the price book entries of the above recommended products
        PricebookEntry[] priceBookEntries = [
            SELECT Id, UnitPrice, Pricebook2Id, Product2Id, Product2.Name, Product2.ProductCode
            FROM PricebookEntry
            WHERE Product2Id IN :recommendedProductIds AND Pricebook2Id = :pricebookId];
        return priceBookEntries;
    }
}

Package Setting

Custom Action Record Update

Notes

Note: Shows a max 2000 records. To sort the records, add a Sort number field to your custom object and update the APEX code to sort by the Sort field.
Note: Doesn’t Support Large Quoting Experience.
Note: The Recommended Products screen uses the Search Results field set on the Product object for its columns.
Note: Supports field level security on fields included in the plugin. Users will not see fields from the Search Results field set they don’t have access to.

Demo

Reference

Comments

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.