Use case: Populate display names and quote lines in Configuration Field Data Set objects
Learn how to set up custom objects and Apex triggers in SFDC to populate the display names of CPQ fields.
As part of the CPQ Managed Package, the functionality of the Configuration Field Data Set object in SFDC is to return the Configuration ID of the configuration, every field variable name used by the blueprint, the value of that field, and the label of that value after every save from the CPQ configurator:
However, there might be some extra necessities about the configuration in CPQ outside of these fields created by the Managed Package that an organization needs for downstream processes. For instance, we might want to populate the display names of the CPQ fields, or easily jump to the Quote Line of the associated Configuration Field Data objects for an easy connection to the BOM.
With a little setup of custom objects and Apex Triggers in SFDC, these fields can automatically be populated after every configuration is saved.
Prerequisites
Enable “Push Config Data to Logik Salesforce Object” in the Admin Settings if you have not done so already. This will start creating the Configuration Field Data Sets objects in SFDC.
Populate the display name
- In SFDC Setup, navigate to the Object Manager.
- Create a new custom object called “LGK Label” with the following attributes:
- Record Name: Logik Label
- Data Type: Auto Number
- Display Format: LGKLB-{0000}
- Allow Search: Checked
- Launch New Custom Tab Wizard after saving this custom object: Checked
- On the New Custom Object Tab page, click the Tab Style field and select any style.
- Click Next, click Next again, and then click Save.
- Click Fields & Relationships on LGK Label, and then click New. Create a new field with the following attributes:
- Data Type: TextArea
- Field Label: label
- Field Name: label
- Click New. Create a new field with the following attributes:
- Data Type: TextArea
- Field Label: variablename
- Field Name: variablename
This new LGK Label object will be where we will host the Field Variable Name and Field Label Name in SFDC. The labels will not automatically be imported. They also must be manually updated/imported every so often with changes and additions to the Fields in CPQ Admin. We will go over methods of bulk import later in this guide.
- In Object Manager, search “Configuration Field Data”.
- Click Fields & Relationships, and then click New. Create a new field with the following attributes:
- Data Type: TextArea
- Field Label: Display name
- Field Name: Display_Name
- Click Triggers, and then click New.
- Paste the following code into the Apex code block:
trigger UpdateConfigurationLabels on LGK__ConfigurationFieldData__c (before insert) { // Step 1: Collect FieldKeys from records to be inserted Set<String> fieldKeys = new Set<String>(); for(LGK__ConfigurationFieldData__c confData : Trigger.new) { fieldKeys.add(confData.LGK__FieldKey__c); } // Step 2: Query LGK_Label__c based on collected FieldKeys Map<String, LGK_Label__c> labelMap = new Map<String, LGK_Label__c>(); for(LGK_Label__c label : [SELECT label__c, variablename__c FROM LGK_Label__c WHERE variablename__c IN :fieldKeys]) { labelMap.put(label.variablename__c, label); } // Step 3: Loop through records to be inserted and update Display_Name__c for(LGK__ConfigurationFieldData__c confData : Trigger.new) { LGK_Label__c matchedLabel = labelMap.get(confData.LGK__FieldKey__c); if(matchedLabel != null) { confData.Display_Name__c = matchedLabel.label__c; } else if(confData.LGK__ValueLabel__c != null) { confData.Display_Name__c = confData.LGK__ValueLabel__c; } }
The framework is complete. Add the new Display Name field to the Configuration Field Data Set layout. All thatʼs left is to import the field label names into the LGK Labels objects. Depending on how you use CPQ Fields, there are three methods of accomplishing this.
|
Manual CPQ Label Creation
|
Pros:
Con: Can be a tedious process for a large number of fields |
|
Bulk Import from exporting all CPQ fields
|
Pros:
Cons:
|
|
Bulk Import from exporting the Blueprint Layout
|
Pros:
Cons:
|
If there are any fields that you’d like to show a different display name than what you have imported, you can easily edit the Label object to whatever label you wish and it will begin populating the Configuration Field Data Sets that way after the update.
Populate the quote line
- In SFDC Setup, Navigate to the Object Manager.
- Search “Configuration Field Data”.
- Click Fields & Relationships, and then click New. Create a new field with the following attributes:
- Data Type: Lookup Relationship
- Related to: Quote Line
- Field Label: Quote Line
- Field Name: Quote_Line
- In Object Manager, search "Quote Line".
- Click Triggers, and then click New.
- Paste the following code into the Apex code block:
trigger PopulateConfigFieldData on SBQQ__QuoteLine__c (after insert, after update) { // Step 1: Collect the Configuration Ids from the new Quote Lines Set<String> configIds = new Set<String>(); Map<String, Id> quoteLineMap = new Map<String, Id>(); // Mapping Configuration UUID to Quote Line Id for (SBQQ__QuoteLine__c ql : Trigger.new) { if (String.isNotBlank(ql.LGK__ConfigurationId__c)) { configIds.add(ql.LGK__ConfigurationId__c); quoteLineMap.put(ql.LGK__ConfigurationId__c, ql.Id); // Storing Quote Line Id } } if (configIds.isEmpty()) { return; } // Step 2: Query the Configuration Field Data records List<LGK__ConfigurationFieldData__c> confFieldsToUpdate = [SELECT Id,LGK__ConfigurationId__c FROM LGK__ConfigurationFieldData__c WHERE LGK__ConfigurationId__c IN:configIds]; // Step 3: Update the Field Data records for (LGK__ConfigurationFieldData__c cf : confFieldsToUpdate) { Id quoteLineId = quoteLineMap.get(cf.LGK__ConfigurationId__c); if (quoteLineId != null) { cf.Quote_Line__c = quoteLineId; // Assigning the Quote Line Id } } update confFieldsToUpdate;
Now, every time a Quote is saved in SFDC, the Quote Line of the Parent Configurable Product will populate into the Configuration Field Data Set. Remember to add this custom field to the Configuration Field Data Sets layout to see it in the tab.