Learn how to utilize Lookup Queries for Product Rules (Selection type). Guest post by Sr. Salesforce Developer Amruta Sinha
When Should I Pair Product Rules with Lookup Queries?
Product rule with lookup queries can be used to query records from a custom object, which can then be used to show validation error message, drive product selection (Enable/Disable/Add/Remove etc.) in the configurator, or update the Quote Line Editor.
Lookup Queries act as a query, or combination of queries, that bring in data from custom object records. Multiple queries work in an AND combination to match Product Option, Quote, or Quote Line fields with Lookup data fields to filter records and control configuration behavior. This is particularly useful when you have fixed matching parameters, or a data set which changes often. Therefore, using Lookup Queries reduces the effort otherwise involved in frequently modifying Product Rules and Conditions.
Example Use Case
A bundled product 4K Video Camera sells multiple options of basic and storage accessories. Country restrictions must be enforced so that Video Editor License and SD Card 512GB are not sellable when the country is United States. By default, SD Card 1TB should be selected for the US.
This scenario can be configured with selection Product Rule and Lookup Query data. To do so, we will walk through the following steps:
- Create a Configuration Attribute on bundle parent product to show ‘Ship To Country’ on configurator page
- Create a custom picklist field Country on Lookup Data (SBQQ__LookupData__c) object. Setup Lookup data records
- Create a selection Product Rule with Lookup Queries to filter matching records
Setup – Step 1, Configuration Attribute
This is not a mandatory step, however it is useful to test different scenarios without going back-and-forth to check ‘Ship To Country’ on quote.
Create a configuration attribute ‘Ship To Country’ on parent bundle product – 4K Video Camera. This will bring ‘Ship To Country’ from the quote and show it in configurator.
Setup – Step 2, Lookup Data Setup
Create a custom picklist field Country (Country__c) on the Lookup Data (SBQQ__LookupData__c) object and create a few records as shown below:
Setup – Step 3, Product Rule
Create a selection Product Rule with fill in Lookup Query Information as shown below:
Lookup queries compare fields on the Lookup object (in this case, Lookup Data) with fields on the Quote, Quote Line, or Product Option.
In the Product Rule’s related list for object ‘Lookup Query’, create a new record to match Quote ‘Ship To Country’ (SBQQ__ShippingCountry__c) with custom field Country (Country__c) created on the Lookup Data object.
A Configuration Rule ties configured Product with a Product Rule to make sure that rule is applied only to a particular product/product bundle.
Note: Product Rule using lookup data ignores Product Feature set in Configuration rule. Lookup data is only filtered based on lookup query parameters (in this case, ‘Ship To Country’==Country).
From the Product Rule related list, create a new Configuration Rule record and select parent bundle product ‘4K Video Camera’ and check Active checkbox.
Walkthrough – Product Rule in Action
Create a quote with ‘Ship To Country’= US and add 4K Video Camera bundle. On the configuration page, ‘Ship To Country’ configuration is set to US (which we set up previously) and Video Editor License is greyed-out so it can’t be selected. Note we could instead hide it by changing Action type on Lookup data record to ‘Hide’.
Note below that SD Card 1TB is selected by default and SD Card 512GB is disabled.
Let’s take this Product Rule one step further by disabling the entire configuration and then driving it through the lookup data instead. All the set up done so far remains as-is, but with a minor change. Create an Action record from the Product Rule related list to disable all of the Product Options in configurator.
Important: If an Action (Product Action) is defined on the Lookup Queries for a Product Rule, then the Action runs first followed by the lookup queries.
Note: If a Product Option doesn’t have a matching record in lookup data object, then it remains disabled in the configurator.
Product Model (ProductModel__c) is a custom text field created on product object which is updated with text ‘High definition Camera’ for all Product Options of 4K Video Camera.
Now let’s go back into the Quote and see how the behavior has changed.
- Camera Mount Microphone – Doesn’t have matching lookup data record, so the ‘Disable’ action holds and the part cannot be selected.
- Pro Audio Boom Microphone, SD Card 256GB – Matching lookup data record with Type = Enable. This makes it available for selection but not selected by default.
- Video Editor License, SD Card 512GB – Matching lookup data record with Type = Disable. So this cannot be selected.
- SD Card 1TB – Matching lookup data record with Type = Enable & Add. This means it is selected and editable.
Product Rule Guidelines
- Product Rule with Actions and Lookup Queries defined, Actions gets precedence in order of execution followed by Lookup Queries.
- Product Features is ignored on the Configuration Rules for Product Rules with Lookup Queries to make sure resultant data set is derived only from the Lookup Queries.
- Dynamic bundles are not affected by Selection and Validation product rules. They only come in effect when saved bundle is reconfigured.
- To make Product Rules work for nested bundles, set Parent Bundle Condition Level = 1 and include nested bundle in Configuration Rule. I plan to provide more detailed information on nested bundles in future posts.
- Define unique lookup data records to avoid runtime error, try adding more fields to drill down to the specific records you are looking for.
Thanks to Amruta for her detailed contribution, and let her know if you have any questions about employing Product Rules w/ Lookup Queries!