Use Whitelist field set - code sample and use case
This task provides a code sample and use case for using the whitelist field set to manage custom fields in Zuora Quotes.
Use the Whitelist field set when a custom field must be available to CPQ X logic, a JavaScript plugin, the Charge Group API, or another headless component but must not be displayed to users in Quote Studio.
The CPQX Quote Information and CPQX Child Quote Information field sets both load fields into the quote data model and render those fields in the Quote Studio user interface. Use a Whitelist field set when the field must be available for processing without being visible to users.
The following code sample demonstrates how the whitelist field set affects the use of custom fields. See Quote Class for information about getInstance global method.
//Assumption: There is a custom text field cf1__c on the zqu__Quote__c object
zqu__Quote__c currentQuote = zqu.Quote.getInstance('<quoteId>').getSObject()
//Scenario 1: The following line will throw an an error
// "SObject row was retrieved via SOQL without querying the requested field".
System.assertEquals('customFieldText', currentQuote.cf1__c);
//Scneario 2: The custom field was added to a Zuora Quotes fieldSet.
// The line should not throw an error.
System.assertEquals('customFieldText', currentQuote.cf1__c);
//Scenario 3: The user registered a whitelist fieldSet
// named "custom_object_fields" and added cf1__c to the fieldSet.
// The line should not throw an error
System.assertEquals('customFieldText', currentQuote.cf1__c);
The following is a sample use case for populating a custom field in the JavaScript plugin using the Whitelist FieldSet Name setting: