Product Configuration Intializer for Guided Selling
The product configuration initializer uses a custom user-provided APEX page to select options and
set field values based on the results of guided selling prompts. It works only for standard
product option fields and not for configuration attributes or custom product option
fields.
To make a product configuration initializer, create a Visualforce controller and a Visualforce page. To use the initializer with your guided selling setup, go to your quote process’s Product Configuration Initializer field and enter c__ followed by your Visualforce page name.
Example
Sample Visualforce
controller:
1public with sharing class LF_ProductInitializerController {
2 public Product2[] products {get; set;}
3 public Boolean skip {get; set;}
4 Map<String,SBQQ__ProductOption__c> optionsByCode = new Map<String,SBQQ__ProductOption__c>();
5
6 public LF_ProductInitializerController() {
7 // Set "skip" to true to bypass the configuration page, or to false to on the config page after the initializer has completed
8 skip = trye;
9
10 // Retrieve product (bundle)
11 String pidsStr = ApexPages.currentPage().getParameters().get('pids');
12 String[] pids = pidsStr.split(',');
13 products = [SELECT Id, Family, (SELECT SBQQ__OptionalSKU__r.ProductCode, SBQQ__Quantity__c, SBQQ__Selected__c FROM SBQQ__Options__r) FROM Product2 WHERE Id IN :pids];
14 for (SBQQ__ProductOption__c opt : products[0].SBQQ__Options__r) {
15 optionsByCode.put(opt.SBQQ__OptionalSKU__r.ProductCode, opt);
16 }
17
18 String myInput1 = ApexPages.currentPage().getParameters().get('Process Input 1');
19 Decimal myInput2 = toInteger(ApexPages.currentPage().getParameters().get('Process Input 2'));
20
21 // Perform any logic you want here
22
23 // Then select options in the bundle, for example:
24 if (myInput1 == 'ABC') {
25 selectOption('MyProductOption1', myInput2);
26 } else {
27 selectOption('MyProductOption2', 1)
28 }
29 }
30
31 private Decimal toInteger(String value) {
32 return String.isBlank(value) ? 0 : Decimal.valueOf(value);
33 }
34
35 private void selectOption(String code, Decimal qty) {
36 optionsByCode.get(code).SBQQ__Selected__c = (qty > 0);
37 optionsByCode.get(code).SBQQ__Quantity__c = qty;
38 }
39}Example
Sample Visualforce page:
1<apex:page controller="LF_ProductInitializerController" contentType="text/xml" showHeader="false" sidebar="false">
2 <products skipConfiguration="{!skip}">
3 <apex:repeat var="product" value="{!products}">
4 <product id="{!product.Id}">
5 <apex:repeat var="opt" value="{!product.SBQQ__Options__r}">
6 <option id="{!opt.Id}"
7 selected="{!opt.SBQQ__Selected__c}"
8 quantity="{!ROUND(opt.SBQQ__Quantity__c, 0)}"/>
9 </apex:repeat>
10 </product>
11 </apex:repeat>
12 </products>
13</apex:page>