Professional Documents
Culture Documents
CPQ Developer Guide
CPQ Developer Guide
Guide
Version 56.0, Winter ’23
PREVIEW
Note: This release is in preview. Features described in this document don’t become generally available
until the latest general availability date that Salesforce announces for this release. Before then, and where @salesforcedocs
features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within Last updated: July 19, 2022
any particular time frame or at all. Make your purchase decisions only on the basis of generally available
products and features.
© Copyright 2000–2022 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark of salesforce.com, inc.,
as are other names and marks. Other marks appearing herein may be trademarks of their respective owners.
CONTENTS
INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
CHAPTER 1 Salesforce CPQ Developer Guide
In this chapter ... Start working with Salesforce CPQ API and plugins.
1
Salesforce CPQ Developer Guide Get Started with Salesforce CPQ API
2
Salesforce CPQ Developer Guide CPQ API Models
3
Salesforce CPQ Developer Guide CPQ API Models
4
Salesforce CPQ Developer Guide CPQ API Models
key Integer Each quote line and group has a key that is
unique amongst all other keys in the same
quote.
5
Salesforce CPQ Developer Guide CPQ API Models
controllingGroups Map<String,Set<Id>> The option IDs that this option depends on.
6
Salesforce CPQ Developer Guide CPQ API Models
7
Salesforce CPQ Developer Guide CPQ API Models
optionId Id The
SBQQ__ProductOption__c.Id.
8
Salesforce CPQ Developer Guide CPQ API Models
9
Salesforce CPQ Developer Guide CPQ API Models
10
Salesforce CPQ Developer Guide CPQ API Models
11
Salesforce CPQ Developer Guide CPQ API Models
12
Salesforce CPQ Developer Guide CPQ API Models
13
Salesforce CPQ Developer Guide CPQ Quote API
14
Salesforce CPQ Developer Guide CPQ Quote API
REST Examples
curl
"https://yourInstance.salesforce.com/services/apexrest/SBQQ/ServiceRouter" -H
"Content-Type: application/json" -H "Authorization: Bearer token" -X POST -d
@quoteModel.json
This request body quoteModel.json file saves a quote. The context value is a JSON formatted string.
{"saver": "SBQQ.QuoteAPI.QuoteSaver", "model": "{\"record\":
{\"attributes\":{\"type\":\"SBQQ__Quote__c\",\"url\":\"/services/data/v41.0/sobjects/
SBQQ__Quote__c/a0l61000003kUlVAAU\"},
15
Salesforce CPQ Developer Guide CPQ Quote API
\"Name\":\"Q-00681\",\"Id\":\"a0l61000003kUlVAAU\"},\"nextKey\":2,\"netTotal\":0.00,\
"lineItems\":[],\"lineItemGroups\":[],\"customerTotal\":0.00}"}
An example response body after saving a quote. The actual response is a JSON formatted string.
{
"record": {
"attributes":{
"type":"SBQQ__Quote__c",
"url":"/services/data/v41.0/sobjects/SBQQ__Quote__c/a0l61000003kUlVAAU"
},
"Name":"Q-00681",
"Id":"a0l61000003kUlVAAU"
},
"nextKey":2,
"netTotal":0.00,
"lineItems":[],
"lineItemGroups":[],
"customerTotal":0.00
}
APEX Examples
Before saving the QuoteSaver example class, make sure that the CPQ Model classes are added as individual Apex classes in your org.
public with sharing class QuoteSaver {
public QuoteModel save(QuoteModel quote) {
String quoteJSON = SBQQ.ServiceRouter.save('SBQQ.QuoteAPI.QuoteSaver',
JSON.serialize(quote));
return (QuoteModel) JSON.deserialize(quoteJSON, QuoteModel.class);
}
}
For an example of the QuoteSaver class, run the following code in anonymous Apex.
QuoteModel quoteModel; //Use Read, Add Products, or Calculate APIs to obtain a QuoteModel
Note: The Calculate Quote API requires callback when evaluating quote-scoped product rules.
16
Salesforce CPQ Developer Guide CPQ Quote API
Formats
JSON, Apex
HTTP Method
PATCH
Authentication
Authorization: Bearer token
REQUEST
Parameter 1
Name: quote
Type: QuoteModel
Required: Yes
Description: Representation of SBQQ__Quote__c data. See CPQ API QuoteModel
Parameter 2
Name: callbackClass
Type: String
Required: Required for Apex Trigger
Description: This Apex class implements the CPQ CalculateCallback interface.
REST Examples
curl
"https://yourInstance.salesforce.com/services/apexrest/SBQQ/ServiceRouter?loader=SBQQ.QuoteAPI.QuoteCalculator"
-H
"Content-Type: application/json" -H "Authorization: Bearer token" -X PATCH -d
"@quoteToCalculate.json"
This request body quoteToCalculate.json file calculates a quote. The context value is a JSON formatted string.
{"context":"{\"quote\":{\"record\":{\"attributes\":{\"type\":\"SBQQ__Quote__c\",
\"url\":\"/services/data/v41.0/sobjects/SBQQ__Quote__c/a0p61000002NUmoAAG\"},
\"SBQQ__PartnerDiscount__c\":null,\"SBQQ__GenerateContractedPrice__c\":null,
\"SBQQ__QuoteProcessId__c\":\"a0m61000005NYxO\",
\"SBQQ__NetAmount__c\":100.0,\"SBQQ__CustomerDiscount__c\":null,
\"SBQQ__CustomerAmount__c\":100.0,\"SBQQ__PaymentTerms__c\":\"Net30\",
\"SBQQ__RenewalUpliftRate__c\":null,\"Name\":\"Q-00822\",\"SBQQ__Type__c\":\"Quote\",
\"SBQQ__SubscriptionTerm__c\":null,\"SBQQ__MarkupRate__c\":null,
\"SBQQ__OrderGroupID__c\":null,\"SBQQ__DistributorDiscount__c\":null,
\"SBQQ__OrderByQuoteLineGroup__c\":false,\"SBQQ__OrderBy__c\":null,
\"SBQQ__PricebookId__c\":\"01s61000000LI67AAG\",\"SBQQ__EndDate__c\":null,
\"SBQQ__Account__c\":null,\"SBQQ__StartDate__c\":null,
\"SBQQ__FirstSegmentTermEndDate__c\":null,\"SBQQ__BillingFrequency__c\":null,
\"SBQQ__LineItemsGrouped__c\":false,\"SBQQ__ExpirationDate__c\":null,
\"SBQQ__Primary__c\":false,\"SBQQ__LineItemCount__c\":1.0,\"SBQQ__MasterContract__c\":null,
\"SBQQ__EditLinesFieldSetName__c\":null,
\"Id\":\"a0p61000002NUmoAAG\",\"SBQQ__Unopened__c\":false,\"SBQQ__RenewalTerm__c\":null},
\"nextKey\":2,\"netTotal\":100.00,
\"netNonSegmentTotal\":100.0000,\"lineItems\":[{\"upliftable\":false,
\"targetCustomerTotal\":null,\"targetCustomerAmount\":null,
17
Salesforce CPQ Developer Guide CPQ Quote API
\"record\":{\"attributes\":{\"type\":\"SBQQ__QuoteLine__c\",
\"url\":\"/services/data/v41.0/sobjects/SBQQ__QuoteLine__c/a0l610000061yHpAAI\"},
\"SBQQ__CarryoverLine__c\":false,\"SBQQ__TermDiscountTier__c\":null,
\"SBQQ__VolumeDiscount__c\":null,\"SBQQ__BillingType__c\":null,
\"SBQQ__Discount__c\":null,\"SBQQ__ListPrice__c\":100.0,\"SBQQ__Existing__c\":false,
\"SBQQ__ProductName__c\":\"Product1\",\"SBQQ__SegmentIndex__c\":null,
\"SBQQ__DiscountTier__c\":null,\"SBQQ__SBCustomLevel__c\":null,\"SBQQ__ComponentTotal__c\":null,
\"SBQQ__RenewedSubscription__c\":null,
\"SBQQ__SubscriptionTargetPrice__c\":null,\"SBQQ__AllowAssetRefund__c\":false,
\"SBQQ__Optional__c\":false,\"SBQQ__PriorQuantity__c\":null,
\"SBQQ__Source__c\":null,\"SBQQ__Quote__c\":\"a0p61000002NUmoAAG\",\"SBQQ__SBCustomEndDate__c\":null,
\"SBQQ__ProratedListPrice__c\":100.0,\"SBQQ__ChargeType__c\":null,
\"SBQQ__UpliftAmount__c\":0.0,\"SBQQ__ComponentSubscriptionScope__c\":null,
\"SBQQ__OptionLevel__c\":null,\"SBQQ__NetPrice__c\":100.0,\"SBQQ__SBCustomCity__c\":null,
\"Id\":\"a0l610000061yHpAAI\",\"SBQQ__OriginalQuoteLineId__c\":null,
\"SBQQ__RegularPrice__c\":100.0,\"SBQQ__EffectiveQuantity__c\":1.0,\"SBQQ__Quantity__c\":1.0,
\"SBQQ__TaxCode__c\":null,\"SBQQ__sbCustom_Number1__c\":null,\"SBQQ__ContractedPrice__c\":null,
\"SBQQ__CostEditable__c\":false,\"SBQQ__Dimension__c\":null,
\"SBQQ__DynamicOptionId__c\":null,\"SBQQ__SBCustomSupport__c\":null,
\"SBQQ__PreviousSegmentUplift__c\":null,\"SBQQ__EndDate__c\":null,\"SBQQ__PreviousSegmentPrice__c\":null,
\"SBQQ__UpgradedSubscription__c\":null,\"SBQQ__SpecialPriceType__c\":null,
\"SBQQ__SegmentKey__c\":null,\"SBQQ__OptionDiscount__c\":null,\"SBQQ__RequiredBy__c\":null,
\"SBQQ__UpgradedAsset__c\":null,\"SBQQ__Bundled__c\":false,\"SBQQ__SBCustomColor__c\":null,
\"SBQQ__OptionType__c\":null,\"SBQQ__Number__c\":1.0,\"SBQQ__SubscriptionPercent__c\":null,
\"SBQQ__ComponentListTotal__c\":null,\"SBQQ__TermDiscountSchedule__c\":null,
\"SBQQ__Taxable__c\":false,\"SBQQ__Description__c\":null,\"SBQQ__ProductCode__c\":\"P1\",
\"SBQQ__OriginalPrice__c\":100.0,\"SBQQ__GenerateContractedPrice__c\":null,
\"SBQQ__NetTotal__c\":100.0,\"SBQQ__UnitCost__c\":null,\"SBQQ__SubscriptionCategory__c\":null,
\"SBQQ__Hidden__c\":false,\"SBQQ__NonDiscountable__c\":false,\"SBQQ__Markup__c\":0.0,\"SBQQ__RenewedAsset__c\":null,
\"SBQQ__GrossProfit__c\":null,\"SBQQ__MinimumPrice__c\":null,
\"SBQQ__BundledQuantity__c\":null,\"SBQQ__BatchQuantity__c\":null,
\"SBQQ__ProrateMultiplier__c\":1.0,\"SBQQ__CustomerPrice__c\":100.0,\"SBQQ__SubscriptionTerm__c\":null,
\"SBQQ__MarkupRate__c\":null,\"SBQQ__DistributorDiscount__c\":null,
\"SBQQ__DefaultSubscriptionTerm__c\":null,\"SBQQ__PriceEditable__c\":false,
\"SBQQ__ProratedPrice__c\":100.0,
\"SBQQ__ComponentUpliftedByPackage__c\":false,\"SBQQ__StartDate__c\":null,
\"SBQQ__NonPartnerDiscountable__c\":false,\"SBQQ__BlockPrice__c\":null,\"SBQQ__MaximumPrice__c\":null,
\"SBQQ__SubscriptionPricing__c\":null,\"SBQQ__AdditionalDiscount__c\":0.0,\"SBQQ__Favorite__c\":null,
\"SBQQ__ProductOption__c\":null,\"SBQQ__OptionDiscountAmount__c\":null,
\"SBQQ__TermDiscount__c\":null,\"SBQQ__MarkupAmount__c\":null,\"SBQQ__PartnerDiscount__c\":null,
\"SBQQ__ComponentDiscountedByPackage__c\":false,\"SBQQ__Renewal__c\":false,
\"SBQQ__CompoundDiscountRate__c\":null,\"SBQQ__UpgradedQuantity__c\":null,
\"SBQQ__AdditionalDiscountAmount__c\":null,\"SBQQ__Cost__c\":null,
\"SBQQ__PackageProductDescription__c\":null,\"SBQQ__PartnerPrice__c\":100.0,\"SBQQ__DiscountSchedule__c\":null,
\"SBQQ__ComponentCost__c\":null,\"SBQQ__SubscribedAssetIds__c\":null,
\"SBQQ__SubscriptionScope__c\":\"Quote\",\"SBQQ__Product__r\":{\"attributes\":
{\"type\":\"Product2\",\"url\":\"/services/data/v41.0/sobjects/Product2/01t610000033JNPAA2\"},
\"SBQQ__ExternallyConfigurable__c\":false,\"SBQQ__CostEditable__c\":false,\
"SBQQ__QuantityEditable__c\":true,\"SBQQ__Hidden__c\":false,\"SBQQ__ExcludeFromOpportunity__c\":false,
\"SBQQ__NonDiscountable__c\":false,\"Name\":\"Product1\",\"PricebookEntries\":
{\"totalSize\":1,\"done\":true,\"records\":[{\"attributes\":{\"type\":\"PricebookEntry\",
\"url\":\"/services/data/v41.0/sobjects/PricebookEntry/01u610000055KTeAAM\"},\
"UnitPrice\":100.0,\"Product2Id\":\"01t610000033JNPAA2\",\"IsActive\":true,
\"Pricebook2Id\":\"01s61000000LI67AAG\",\"Id\":\"01u610000055KTeAAM\"}]},
18
Salesforce CPQ Developer Guide CPQ Quote API
\"SBQQ__AssetConversion__c\":\"Oneperquoteline\",\"SBQQ__IncludeInMaintenance__c\":false,
\"SBQQ__PriceEditable__c\":false,\"SBQQ__ReconfigurationDisabled__c\":false,
\"SBQQ__DescriptionLocked__c\":false,\"SBQQ__NewQuoteGroup__c\":false,\"SBQQ__Optional__c\":false,
\"SBQQ__ExcludeFromMaintenance__c\":false,
\"SBQQ__AssetAmendmentBehavior__c\":\"Default\",\"ProductCode\":\"P1\",\"SBQQ__OptionSelectionMethod__c\":\"Click\",
\"SBQQ__SubscriptionType__c\":\"Renewable\",\"SBQQ__SubscriptionBase__c\":
\"List\",\"SBQQ__CustomConfigurationRequired__c\":false,\"SBQQ__NonPartnerDiscountable__c\":false,
\"SBQQ__DefaultQuantity__c\":1.0,\"SBQQ__PricingMethodEditable__c\":false,\"SBQQ__BlockPricingField__c\
":\"Quantity\",\"SBQQ__HasConfigurationAttributes__c\":false,\"SBQQ__Taxable__c\":false,
\"SBQQ__PricingMethod__c\":\"List\",\"Id\":\"01t610000033JNPAA2\"},\"SBQQ__SubscriptionBase__c\
":\"List\",\"SBQQ__BillingFrequency__c\":null,\"SBQQ__OriginalUnitCost__c\":null,
\"SBQQ__sbcustom_TwinField__c\":null,\"SBQQ__Bundle__c\":false,\"SBQQ__Product__c\":\
"01t610000033JNPAA2\",\"SBQQ__SpecialPrice__c\":100.0,\"SBQQ__PricingMethodEditable__c\":false,
\"SBQQ__Uplift__c\":0.0,\"SBQQ__PackageProductCode__c\":null,\"SBQQ__PricingMethod__c\":\"List\",
\"SBQQ__SegmentLabel__c\":null,\"SBQQ__AdditionalQuantity__c\":null,
\"SBQQ__DiscountScheduleType__c\":null},\"reconfigurationDisabled\":false,\"productQuantityScale\"
:null,\"productQuantityEditable\":true,\"productHasDimensions\":false,
\"parentItemKey\":null,\"parentGroupKey\":null,\"key\":2,\"dimensionType\":null,\"descriptionLocked\":false,
\"configurationType\":null,\"configurationEvent\":null,
\"amountDiscountProrated\":null}],\"lineItemGroups\":[],\"customerTotal\":100.00,\"channelDiscountsOffList\":false,
\"applyPartnerDiscountFirst\":false,\"applyAdditionalDiscountLast\":false}}"}
An example response body after successfully calculating a product. The actual response is a JSON formatted string.
{
"record": {
"attributes": {
"type": "SBQQ__Quote__c",
"url": "/services/data/v41.0/sobjects/SBQQ__Quote__c/a0p610000040iumAAA"
},
"Id": "a0p61000002NUmoAAG",
"Name": "Q-00822"
},
"nextKey": 2,
"netTotal": 200,
"netNonSegmentTotal": 200,
"lineItems": [
{
"record": {
"attributes": {
"type": "SBQQ__QuoteLine__c",
"url": "/services/data/v41.0/sobjects/SBQQ__QuoteLine__c/a0l61000003u09UAAQ"
},
"Id": "a0l610000061yHpAAI",
"SBQQ__NetTotal__c": 200
}
}
"lineItemGroups": []
}
19
Salesforce CPQ Developer Guide CPQ Quote API
Apex Examples
When you execute the Calculate API with an Apex trigger, you also need to create a quote calculator callback class. This class must
implement the CPQ CalculateCallback interface to save the quote after calculating it in the background.
global with sharing class MyCallback implements SBQQ.CalculateCallback {
global void callback(String quoteJSON){
SBQQ.ServiceRouter.save('SBQQ.QuoteAPI.QuoteSaver', quoteJSON);
}
}
Before saving the QuoteCalculator example class, make sure that the CPQ model classes are added as individual Apex classes in your
org.
public with sharing class QuoteCalculator {
For an example of the QuoteCalculator class, run the following code in anonymous Apex.
QuoteModel quoteModel; // Use Read or Add Products APIs to obtain a QuoteModel
quoteModel.lineItems[0].record.SBQQ__Quantity__c = 2;
QuoteCalculator calculator = new QuoteCalculator();
calculator.calculate(quoteModel, 'MyCallback');
20
Salesforce CPQ Developer Guide CPQ Quote API
Parameter 1
Name: uid
Type: String
Required: Yes
Description: The ID of the quote to read
RESPONSE
Type
QuoteModel
Description
The representation of SBQQ__Quote__c data.
REST Examples
curl "https://yourInstance.salesforce.com/services/apexrest/SBQQ/
ServiceRouter?reader=SBQQ.QuoteAPI.QuoteReader&uid=a0p610000040iumAAA"
-H "Content-Type: application/json" -H "Authorization: Bearer token" -X GET
An example response body after reading a quote. The actual response is a JSON formatted string.
{
"record": {
"attributes": {
"type": "SBQQ__Quote__c",
"url": "/services/data/v41.0/sobjects/SBQQ__Quote__c/a0p610000040iumAAA"
},
"Id": "a0p610000040iumAAA",
"Name": "Q-00880"
},
"nextKey": 5,
"netTotal": 300,
"netNonSegmentTotal": 300,
"lineItems": [
{
"record": {
"attributes": {
"type": "SBQQ__QuoteLine__c",
"url":
"/services/data/v41.0/sobjects/SBQQ__QuoteLine__c/a0l61000003u09UAAQ"
},
"Id": "a0l61000003u09UAAQ"
}
}
"lineItemGroups": [ ]
}
21
Salesforce CPQ Developer Guide CPQ Quote API
Apex Examples
Before saving the QuoteReader example class, make sure that the CPQ model classes are as individual Apex classes in your org.
public with sharing class QuoteReader {
For an example of the QuoteReader class, run the following code in anonymous Apex.
QuoteReader reader = new QuoteReader();
QuoteModel quote = reader.read('a0Wf100000J1vk1');
System.debug(quote);
REST Examples
curl
"https://yourInstance.salesforce.com/services/apexrest/SBQQ/ServiceRouter?loader=QuoteAPI.QuoteValidator"
-H
"Content-Type: application/json" -H "Authorization: Bearer token" -X PATCH -d
@quoteModel.json
22
Salesforce CPQ Developer Guide CPQ Quote API
The request body quoteModel.json file validates a quote. The context value is a JSON formatted string/serialization of a quote,
the same as the CPQ Save Quote API.
{"context": "{\"record\":
{\"attributes\":{\"type\":\"SBQQ__Quote__c\",\"url\":\"/services/data/v41.0/sobjects/SBQQ__Quote__c/a0l61000003kUlVAAU\"},
\"Name\":\"Q-00681\",\"Id\":\"a0l61000003kUlVAAU\"},\"nextKey\":2,\"netTotal\":0.00,\"lineItems\":[],\"lineItemGroups\":[],\"customerTotal\":0.00}"}
An example response body after creating the Apex job for generating the quote proposal.
// valid quote
[]
// invalid quote
[
"message 1",
"message 2",
"message 3"
]
Apex Examples
Before saving the Validator example class, make sure that the CPQ model classes are added as individual Apex classes in your org.
public with sharing class Validator {
Run the following code in anonymous Apex to get Apex job ID for generating and saving the quote proposal.
QuoteModel quoteModel; //Use Read Quote API to obtain a QuoteModel
23
Salesforce CPQ Developer Guide CPQ Quote API
Parameter 1
Name: quote
Type: QuoteModel
Required: Yes
Description: A representation of SBQQ__Quote__c data
Parameter 2
Name: products
Type: ProductModel[]
Required: Yes
Description: An array of representations of product data
Parameter 3
Name: groupKey
Type: Integer
Required: Required only for grouped quotes
Description: An index of the existing quote line group where you’re adding products (0 indexed by default)
Parameter 4
Name: ignoreCalculate
Type: Boolean
Required: Yes
Description: Always use true for this value
RESPONSE
Type
QuoteModel
Description
The representation of SBQQ__Quote__c data
REST Examples
curl
"https://yourInstance.salesforce.com/services/apexrest/SBQQ/ServiceRouter?loader=SBQQ.QuoteAPI.QuoteProductAdder"
This request body adderContext.json file reads a product. The context value is a JSON formatted string.
{"context":"{\"quote\":{\"record\":{\"attributes\":{\"type\":\"SBQQ__Quote__c\",\"url\":\"/services/data/v41.0/sobjects/SBQQ__Quote__c/a0p61000004IpR8AAK\"},
\"Name\":\"Q-00905\",\"Id\":\"a0p61000004IpR8AAK\"},\"nextKey\":2,\"netTotal\":0.00,\"lineItems\":[],\"lineItemGroups\":[],
\"customerTotal\":0.00},\"products\":[],\"groupKey\":0, \"ignoreCalculate\": true}"}
An example response body after adding a product. The actual response is a JSON formatted string.
{
"record": {
"attributes": {
24
Salesforce CPQ Developer Guide CPQ Quote API
"type": "SBQQ__Quote__c",
"url": "/services/data/v41.0/sobjects/SBQQ__Quote__c/a0p61000004IpR8AAK"
}
},
"nextKey": 4,
"netTotal": 0.00,
"lineItems": [
{
"record": {
"attributes": {
"type": "SBQQ__QuoteLine__c"
},
"SBQQ__Product__c": "01t610000033JNtAAM"
},
"productQuantityEditable": true,
"productHasDimensions": false,
"key": 3,
"descriptionLocked": false
},
{
"record": {
"attributes": {
"type": "SBQQ__QuoteLine__c"
},
"SBQQ__Product__c": "01t610000033JNUAA2",
"SBQQ__Product__r": {
"attributes": {
"type": "Product2",
"url": "/services/data/v41.0/sobjects/Product2/01t610000033JNUAA2"
},
"Id": "01t610000033JNUAA2",
"Name": "Product 2",
"ProductCode": "P2"
}
}
}
],
"lineItemGroups": [
{
"record": {
"attributes": {
"type": "SBQQ__QuoteLineGroup__c",
"url": "/services/data/v41.0/sobjects/SBQQ__QuoteLineGroup__c/a0k61000008WIF1AAO"
},
"SBQQ__Quote__c": "a0p61000004IpR8AAK",
"Id": "a0k61000008WIF1AAO",
"SBQQ__Number__c": 1.0,
"SBQQ__SeparateContract__c": false,
"Name": "Group1"
},
"key": 2,
"hasMultiSegmentLines": false
}
25
Salesforce CPQ Developer Guide CPQ Quote API
],
"customerTotal": 0.00
}
Apex Examples
Before saving the ProductAdder example class, make sure that the CPQ model classes are added as individual Apex classes in your org.
public with sharing class ProductAdder {
For an example of the ProductAdder, run the following code in anonymous Apex.
QuoteModel quoteModel; //Use Read Quote API to obtain a QuoteModelProductModel
productModel; //Use Read Product API to obtain a ProductModel
26
Salesforce CPQ Developer Guide CPQ Quote API
Authentication
Authorization: Bearer token
REQUEST
Parameter 1
Name: productId
Type: ID
Required: Yes
Description: The ID of the product record to load
Parameter 2
Name: pricebookId
Type: ID
Required: Yes
Description: The ID of the pricebook that contains the product record to load
Parameter 3
Name: currencyCode
Type: String
Required: Required only for multi-currency orgs
Description: The ISO code of a Salesforce currency where the product’s price is loaded
RESPONSE
Type
ProductModel
Description
The representation of product data
REST Examples
curl
"https://yourInstance.salesforce.com/services/apexrest/SBQQ/ServiceRouter?loader=SBQQ.ProductAPI.ProductLoader&uid=01t610000033JNt"
-H "Content-Type: application/json" -H "Authorization: Bearer token" -X PATCH -d
"@loaderContext.json"
This request body loaderContext.json file reads a product. The context value is a JSON formatted string.
{"context" : "{\"pricebookId\": \"01sA0000000wuhg\", \"currencyCode\":\"USD\"}"}
An example response body after reading a product. The actual response is a JSON formatted string.
{
"record": {
"attributes": {
"type": "Product2",
"url": "/services/data/v42.0/sobjects/Product2/01tA0000005uzfZ"
},
"Id": "01tA0000005uzfZ",
"Name": "Apple"
}
27
Salesforce CPQ Developer Guide CPQ Quote API
"options": [],
"features": [],
"configuration": {}
}
Apex Examples
Before saving the ProductReader example class, make sure that the CPQ model classes are added as individual Apex classes in your org.
public with sharing class ProductReader {
For an example of the ProductReader class, run the following code in anonymous Apex.
ProductReader reader = new ProductReader();
ProductModel product = reader.read('01tj0000003P1SN','01sj0000003THhKAAW','USD');
System.debug(product);
28
Salesforce CPQ Developer Guide CPQ Quote API
Required: No
Description: The document name
Parameter 2
Name: paperSize
Type: String
Required: No
Description: Options: Default, Letter, Legal, A4
Parameter 3
Name: outputFormat
Type: String
Required: No
Description: Options: pdf, word. Defaults to pdf.
Parameter 4
Name: quoteID
Type: Id
Required: Yes
Description: The quote ID
Parameter 5
Name: templateId
Type: Id
Required: Yes
Description: The quote template ID
Parameter 6
Name: language
Type: String
Required: No
Description: Defaults to en_US
RESPONSE
Type
jobId
Description
Apex queueable job Id
REST Examples
curl
"https://yourInstance.salesforce.com/services/apexrest/SBQQ/ServiceRouter?saver=QuoteDocumentAPI.SaveProposal"
-H "Content-Type: application/json" -H
"Authorization: Bearer token" -X PATCH -d @data.json
29
Salesforce CPQ Developer Guide CPQ Quote API
The request body data.json file generates and saves a quote proposal.
"{\"saver\":\"SBQQ.QuoteDocumentAPI.Save\",\"model\":\"{\\\"name\\\":\\\"test\\\",\\\
"quoteId\\\":\\\"a0n0R000000jhVC\\\",\\\"templateId\\\":\\\"a0l0R000000vahe\\\",
\\\"outputFormat\\\":\\\"PDF\\\",\\\"language\\\":\\\"en_US\\\",\\\"paperSize\\\":\\\"Default\\\"}\"}"
An example response body after creating the Apex job for generating the quote proposal.
"7070R00000Nj8mjQAB"
Apex Examples
Before saving the GenerateQuoteProposal example class, make sure that the CPQ model classes are added as individual Apex classes in
your org.
public with sharing class GenerateQuoteProposal {
Run the following code in anonymous Apex to get Apex job ID for generating and saving the quote proposal.
QuoteProposalModel model = new QuoteProposalModel();
model.quoteId = 'a0n0R000000jhVC';
model.templateId = 'a0l0R000000vahe';
GenerateQuoteProposal proposalGenerator = new GenerateQuoteProposal();
String jobId = proposalGenerator.save(model);
System.debug(jobId);
30
Salesforce CPQ Developer Guide CPQ Quote API
Type: Id
Required: Optional
Description: The quote template record's ID
Parameter 3
Name: language
Type: String
Required: Optional
Description: Language code when using CPQ translations.
RESPONSE
Type
QuoteTermModel
Description
The representation of SBQQ__QuoteTerm__c data
REST Examples
curl "https://yourInstance.salesforce.com/services/apexrest/SBQQ/
ServiceRouter?loader=SBQQ.QuoteTermAPI.Load&uid=a0x5C000000G1CV"
-H "Content-Type: application/json" -H "Authorization: Bearer token" -X PATCH -d
"@termContext.json"
Example request body termContext.json file for reading quote terms. The context value is a JSON formatted string.
{"context":"{\"templateId\": \"a0v5C000000jTgr\", \"language\": \"es\"}"}
An example response body returning two quote terms. The actual response is a JSON formatted string.
[
{
"value": "Hasta 10 sesiones concurrentes incluidas.",
"type": "Standard",
"standardTermId": null,
"quoteId": null,
"locked": false,
"label": "1",
"id": "a0w5C000000cbaFQAQ"
},
{
"value": "$ 50USD / por mes por licencia de sesión adicional.",
"type": "Standard",
"standardTermId": null,
"quoteId": null,
"locked": false,
"label": "1.1",
"id": "a0w5C000000cbaKQAQ"
}
]
31
Salesforce CPQ Developer Guide CPQ Configuration API
Apex Examples
Before saving the QuoteTermReader example class, make sure that the CPQ model classes are added as individual Apex classes in your
org.
public with sharing class QuoteTermReader {
For an example of the QuoteTermReader class, run the following code in anonymous Apex.
QuoteTermReader quoteTermReader = new QuoteTermReader();
List<QuoteTermModel> quoteTerms = quoteTermReader.load('a0x5C000000G1CV', 'a0v5C000000jTgr',
'es');
System.debug(quoteTerms);
32
Salesforce CPQ Developer Guide CPQ Configuration API
RESPONSE
Type Description
ProductModel Representation of product data. See CPQ Models.
REST Examples
curl
"https://*yourInstance*.salesforce.com/services/apexrest/SBQQ/ServiceRouter?loader=SBQQ.ConfigAPI.ConfigLoader&uid=a0x5C000000G1CV"
\
-H "Content-Type: application/json" \
-H "Authorization: Bearer yourAuthorizationToken" \
-X PATCH \
-d "@configLoaderContext.json”
The example request body configLoaderContext.json file for loading product data. This example context value is a JSON
formatted string of the quote model.
{"context":"{\"quote\":{\"record\":{\"attributes\":{\"type\":\"SBQQ__Quote__c\",
\"url\":\"/services/data/v48.0/sobjects/SBQQ__Quote__c/a0p61000004IpR8AAK\"},
\"Name\":\"Q-00905\",
\"Id\":\"a0p61000004IpR8AAK\"},
\"nextKey\":2,
33
Salesforce CPQ Developer Guide CPQ Configuration API
\"netTotal\":0.00,
\"lineItems\":[],
\"lineItemGroups\":[],
\"customerTotal\":0.00},
\"products\":[],
\"groupKey\":0,
\"ignoreCalculate\": true}"}
Example response body returning product data. The actual response is a JSON formatted string.
{
"record": {
"attributes": {
"type": "Product2",
"url": "/services/data/v42.0/sobjects/Product2/01tA0000005uzfZ"
},
"Id": "01tA0000005uzfZ",
"Name": "Apple"
}
"options": [],
"features": [],
"configuration": {}
}
APEX Examples
Before saving the ConfigLoader example class, make sure that the CPQ Modelsclasses are added as individual Apex classes in your
org.
public with sharing class ConfigLoader {
public ProductModel load(Id productId, QuoteModel quote, ProductModel parentProduct)
{
ConfigLoadContext ctx = new ConfigLoadContext(quote, parentProduct);
String productJSON = SBQQ.ServiceRouter.load('SBQQ.ConfigAPI.ConfigLoader',
productId, JSON.serialize(ctx));
return (ProductModel) JSON.deserialize(productJSON, ProductModel.class);
}
To demonstrate usage of the ConfigLoader class, run the following code in anonymous Apex.
QuoteModel quote; //Use Read, Add Products, or Calculate APIs to obtain a QuoteModel
34
Salesforce CPQ Developer Guide CPQ Configuration API
RESPONSE
Type Description
ProductModel Representation of product data.See CPQ Models.
35
Salesforce CPQ Developer Guide CPQ Configuration API
REST Examples
curl
"https://*yourInstance*.salesforce.com/services/apexrest/SBQQ/ServiceRouter?loader=SBQQ.ConfigAPI.LoadRuleExecutor&uid=a0x5C000000G1CV"
\
-H "Content-Type: application/json" \
-H "Authorization: Bearer yourAuthorizationToken" \
-X PATCH \
-d "@loadRuleContext.json"
The example request body loadRuleContext.json file for running load product rules. This example context value is a
JSON-formatted string of the quote model and the configuration model.
{"context":"{\"quote\":{\"record\":{\"attributes\":{\"type\":\"SBQQ__Quote__c\"},
\"Account__c\":\"0014M00001mfEYT\",
\"Id\":\"a0c4M00000eE9SgQAK\",
\"PricebookId__c\":\"01s61000002xO1h\",
\"CurrencyIsoCode\":\"USD\"}},
\"configuration\":{\"validationMessages\":[],
\"priceEditable\":false,
\"optionData\":{\"attributes\":{\"type\":\"SBQQ__ProductOption__c\"}},
\"optionConfigurations\":[{\"validationMessages\":[],
\"priceEditable\":false,
\"optionId\":\"a0U4M00000GJagGUAT\",
\"optionData\":{\"attributes\":{\"type\":\"SBQQ__ProductOption__c\",
\"url\":\"\/services\/data\/v48.0\/sobjects\/ProductOption__c\/a0U4M00000GJagGUAT\"},
\"ConfiguredSKU__c\":\"01t4M000003ru2OQAQ\",
\"Id\":\"a0U4M00000GJagGUAT\",
\"OwnerId\":\"0056100000148O6AAI\",
\"IsDeleted\":false,
\"CurrencyIsoCode\":\"USD\",
\"SystemModstamp\":\"2020-03-10T20:47:39.000+0000\",
\"AppliedImmediately__c\":false,
\"Bundled__c\":false,
\"DiscountedByPackage__c\":false,
\"Number__c\":1,
\"OptionalSKU__c\":\"01t4M000003ru2PQAQ\",
\"PriceEditable__c\":\"No\",
\"ProductConfigurationType__c\":\"Allowed\",
\"ProductName__c\":\"W-7145106 Bundle - Nested Option - Level 1 Product #1\",
\"QuantityEditable__c\":true,
\"Quantity__c\":1,
\"Required__c\":false,
\"Selected__c\":true,
\"System__c\":false,
\"Type__c\":\"Component\",
\"UpliftedByPackage__c\":false,
\"CanOrderSeparately__c\":false},
\"optionConfigurations\":[],
\"isUpgrade\":false,
\"isDynamicOption\":false,
\"configuredProductId\":\"01t4M000003ru2PQAQ\",
\"configured\":false,
\"configurationEntered\":false,
36
Salesforce CPQ Developer Guide CPQ Configuration API
\"configurationData\":{\"attributes\":{\"type\":\"SBQQ__ProductOption__c\"}},
\"changedByProductActions\":false}],
\"isUpgrade\":false,
\"isDynamicOption\":false,
\"configuredProductId\":\"01t4M000003ru2OQAQ\",
\"configured\":false,
\"configurationEntered\":false,
\"configurationData\":{\"attributes\":{\"type\":\"SBQQ__ProductOption__c\"}},
\"changedByProductActions\":false}}"}
Example response body returning product data. The actual response is a JSON formatted string.
{
"record": {
"attributes": {
"type": "Product2",
"url": "/services/data/v42.0/sobjects/Product2/01tA0000005uzfZ"
},
"Id": "01tA0000005uzfZ",
"Name": "Apple"
}
"options": [],
"features": [],
"configuration": {}
}
APEX Examples
Before saving the LoadRuleRunner example class, make sure that the CPQ Models classes are added as individual Apex classes in your
Salesforce org.
public with sharing class LoadRuleRunner {
public ProductModel load(
Id productId,
QuoteModel quote,
Integer lineItemKey,
List<String> dynamicOptionSkus,
ConfigurationModel configuration,
ProductModel parentProduct) {
37
Salesforce CPQ Developer Guide CPQ Configuration API
public LoadRuleRunnerContext(
QuoteModel quote,
Integer lineItemKey,
List<String> dynamicOptionSkus,
ConfigurationModel configuration,
ProductModel parentProduct) {
this.quote = quote;
this.parentProduct = parentProduct;
this.lineItemKey = lineItemKey;
this.dynamicOptionSkus = dynamicOptionSkus;
this.configuration = configuration;
}
}
}
To demonstrate usage of the LoadRuleRunner class, run the following code in anonymous Apex.
QuoteModel quote; //Use Read, Add Products, or Calculate APIs to obtain a QuoteModel
ProductModel product; //Use Read Product or Configuration Loader API to obtain a ProductModel
38
Salesforce CPQ Developer Guide CPQ Configuration API
RESPONSE
Type Description
ConfigurationModel The product's configuration data. This is the same Configuration
Model that was passed in the request, but the data will be changed
based on Product Actions from Product and Price Rules that ran.
See CPQ Models.
REST Examples
curl
"https://yourInstance.salesforce.com/services/apexrest/SBQQ/ServiceRouter?loader=SBQQ.ConfigAPI.ConfigurationValidator&uid=a0x5C000000G1CV
\
-H "Content-Type: application/json" \
-H "Authorization: Bearer yourAuthorizationToken" \
-X PATCH \
-d "@configValidatorContext.json”
The example request body configValidatorContext.json file for running product and price rules. This example context
value is a JSON-formatted string of the quote model, configuration model, and event type.
{"context":"{\"quote\":{\"record\":{\"attributes\":{\"type\":\"SBQQ__Quote__c\"},
\"Account__c\":\"0012F00000ayBPwQAM\",
\"Id\":\"a0z2F000000xGLpQAM\",
\"PricebookId__c\":\"01s2F0000011yApQAI\",
\"CurrencyIsoCode\":\"USD\"}},
\"configuration\":{\"validationMessages\":[],
\"priceEditable\":false,
\"optionData\":{\"attributes\":{\"type\":\"SBQQ__ProductOption__c\"}},
\"optionConfigurations\":[{\"validationMessages\":[],
\"priceEditable\":false,
\"optionId\":\"a0o2F000001Yi4JQAS\",
\"optionData\":{\"attributes\":{\"type\":\"SBQQ__ProductOption__c\",
\"url\":\"\/services\/data\/v48.0\/sobjects\/ProductOption__c\/a0o2F000001Yi4JQAS\"},
\"ConfiguredSKU__c\":\"01t2F000004XoPLQA0\",
\"Id\":\"a0o2F000001Yi4JQAS\",
\"OwnerId\":\"0056100000148O6AAI\",
\"IsDeleted\":false,
\"CurrencyIsoCode\":\"USD\",
\"SystemModstamp\":\"2020-03-10T20:47:39.000+0000\",
39
Salesforce CPQ Developer Guide CPQ Configuration API
\"AppliedImmediately__c\":false,
\"Bundled__c\":false,
\"DiscountedByPackage__c\":false,
\"Number__c\":1,
\"OptionalSKU__c\":\"01t4M000003ru2PQAQ\",
\"PriceEditable__c\":\"No\",
\"ProductConfigurationType__c\":\"Allowed\",
\"ProductName__c\":\"Nested Option Product #1\",
\"QuantityEditable__c\":true,
\"Quantity__c\":1,
\"Required__c\":false,
\"Selected__c\":true,
\"System__c\":false,
\"Type__c\":\"Component\",
\"UpliftedByPackage__c\":false,
\"CanOrderSeparately__c\":false},
\"optionConfigurations\":[],
\"isUpgrade\":false,
\"isDynamicOption\":false,
\"configuredProductId\":\"01t2F000004XoPLQA0\",
\"configured\":false,
\"configurationEntered\":false,
\"configurationData\":{\"attributes\":{\"type\":\"SBQQ__ProductOption__c\"}},
\"changedByProductActions\":false}],
\"isUpgrade\":false,
\"isDynamicOption\":false,
\"configuredProductId\":\"01t2F000004XoPLQA0\",
\"configured\":false,
\"configurationEntered\":false,
\"configurationData\":{\"attributes\":{\"type\":\"SBQQ__ProductOption__c\"}},
\"changedByProductActions\":false},
\"event\":\"Edit\"}"}
Example response body returning product configuration data. The actual response is a JSON formatted string.
{
"validationMessages": ["Incorrect quantity for Product A"],
"priceEditable": false,
"optionId": null,
"optionData": {
"attributes": {
"type": "SBQQ_ProductOption_c"
}
},
"optionConfigurations": [],
"listPrice": null,
"isUpgrade": false,
"isDynamicOption": false,
"inheritedConfigurationData": null,
"hiddenOptionIds": null,
"dynamicOptionKey": null,
"disabledOptionIds": null,
"configuredProductId": "01t3D000005Th8oQAC",
"configured": false,
"configurationData": {
40
Salesforce CPQ Developer Guide CPQ Configuration API
"attributes": {
"type": "SBQQ_ProductOption_c"
},
"SBQQ_UnitPrice_c": null
},
"changedByProductActions": false
}
APEX Examples
Before saving the ConfigValidator example class, make sure that the CPQ Modelsclasses are added as individual Apex classes in
your org.
public with sharing class ConfigValidator {
public ConfigurationModel load(
Id productId,
QuoteModel quote,
ConfigurationModel configuration,
String event,
String upgradedAssetId) {
public ValidatorContext(
QuoteModel quote,
ConfigurationModel configuration,
String event,
String upgradedAssetId) {
this.quote = quote;
this.configuration = configuration;
this.event = event;
this.upgradedAssetId = upgradedAssetId;
}
}
}
41
Salesforce CPQ Developer Guide CPQ Contract API
To demonstrate usage of the ConfigValidator class, run the following code in anonymous Apex.
QuoteModel quote; //Use Read, Add Products, or Calculate APIs to obtain a QuoteModel
ProductModel product; //Use Read Product or Configuration Loader API to obtain a
ProductModel
42
Salesforce CPQ Developer Guide CPQ Contract API
RESPONSE
Type
QuoteModel
Description
Representation of SBQQ__Quote__c data for an amendment quote
REST Examples
curl
"https://yourInstance.salesforce.com/services/apexrest/SBQQ/ServiceRouter?loader=SBQQ.ContractManipulationAPI.ContractAmender&uid=800R00000000X4g"
An example response body after amending a quote. The actual response is a JSON formatted string.
{
"record": {
"attributes": {
"type": "SBQQ__Quote__c",
"url": "/services/data/v41.0/sobjects/SBQQ__Quote__c/a0p610000040iumAAA"
},
"Id": "a0p610000040iumAAA",
"Name": "Q-00880"
},
"nextKey": 5,
"netTotal": 300,
"netNonSegmentTotal": 300,
"lineItems": [
{
"record": {
"attributes": {
"type": "SBQQ__QuoteLine__c",
"url":
"/services/data/v41.0/sobjects/SBQQ__QuoteLine__c/a0l61000003u09UAAQ"
},
"Id": "a0l61000003u09UAAQ"
}
}
"lineItemGroups": [ ]
}
An example response body after amending a quote. The actual response is a JSON formatted string.
{
"record": {
"attributes": {
"type": "SBQQ__Quote__c",
"url": "/services/data/v41.0/sobjects/SBQQ__Quote__c/a0p61000004IpR8AAK"
}
},
"nextKey": 4,
"netTotal": 0.00,
"lineItems": [
43
Salesforce CPQ Developer Guide CPQ Contract API
{
"record": {
"attributes": {
"type": "SBQQ__QuoteLine__c"
},
"SBQQ__Product__c": "01t610000033JNtAAM"
},
"productQuantityEditable": true,
"productHasDimensions": false,
"key": 3,
"descriptionLocked": false
},
{
"record": {
"attributes": {
"type": "SBQQ__QuoteLine__c"
},
"SBQQ__Product__c": "01t610000033JNUAA2",
"SBQQ__Product__r": {
"attributes": {
"type": "Product2",
"url": "/services/data/v41.0/sobjects/Product2/01t610000033JNUAA2"
},
"Id": "01t610000033JNUAA2",
"Name": "Product 2",
"ProductCode": "P2"
}
}
}
],
"lineItemGroups": [
{
"record": {
"attributes": {
"type": "SBQQ__QuoteLineGroup__c",
"url": "/services/data/v41.0/sobjects/SBQQ__QuoteLineGroup__c/a0k61000008WIF1AAO"
},
"SBQQ__Quote__c": "a0p61000004IpR8AAK",
"Id": "a0k61000008WIF1AAO",
"SBQQ__Number__c": 1.0,
"SBQQ__SeparateContract__c": false,
"Name": "Group1"
},
"key": 2,
"hasMultiSegmentLines": false
}
],
"customerTotal": 0.00
}
44
Salesforce CPQ Developer Guide CPQ Contract API
Apex Examples
Note: Before saving the ContractAmender example class, make sure that the CPQ model classes are added as individual Apex
classes in your org.
In this example, the amendment context isn’t used.
public with sharing class ContractAmender {
public QuoteModel load(String contractId) {
String quoteJSON =
SBQQ.ServiceRouter.load('SBQQ.ContractManipulationAPI.ContractAmender', contractId, null);
String quoteJSON =
SBQQ.ServiceRouter.load('SBQQ.ContractManipulationAPI.ContractAmender', contractId, context);
{"attributes":{"type":"SBQQ__Quote__c","url":"/services/data/v50.0/sobjects/SBQQ__Quote__c/12345"},"Id":"12345"}
45
Salesforce CPQ Developer Guide CPQ Contract API
Parameter 1
Name: context
Type: RenewalContext
Required: Yes
Description: JSON object containing the contracts to renew. Include the IDs of each contract to renew. If there’s more than one
contract, include the ID of the contract to use as the main contract.
Attribute 1
Name: masterContractId
Type: Id
Required: No
Description: If you’re renewing multiple contracts, specify the ID of the main contract.
Attribute 2
Name: renewedContracts
Type: ContractModel[]
Required: Yes
Description: One or more ContractModels to renew.
Attribute 3
Available in: Salesforce CPQ Winter ’21 and later
Name: returnOnlyQuoteId
Type: boolean
Required: No
Description: If true, return the ID of the renewed quotes. If false or null, return the information for the renewed quotes.
Default value is false.
RESPONSE
If returnOnlyQuoteId is false or null:
46
Salesforce CPQ Developer Guide CPQ Contract API
Type
QuoteModel[]
Description
Representation of one or more SBQQ__Quote__c data for renewal quotes.
RESPONSE
If returnOnlyQuoteId is true:
Type
integer
Description
The ID of the SBQQ__Quote__c record.
REST Examples
curl
"https://yourInstance.salesforce.com/services/apexrest/SBQQ/ServiceRouter?loader=SBQQ.ContractManipulationAPI.ContractRenewer"
-H
"Content-Type: application/json" -H "Authorization: Bearer token" -X POST -d
@context.json
This request body context.json file renews one or more Contracts. The context value is a JSON formatted string.
{"context": "{\"masterContractId\": null, \"renewedContracts\":
[{\"attributes\":{\"type\":\"Contract\"},\"Id\":\"800540000006LLVAA2\"}]}"}
An example response body after renewing a quote. The actual response is a JSON formatted string.
[{
"record": {
"attributes": {
"type": "SBQQ__Quote__c",
"url": "/services/data/v41.0/sobjects/SBQQ__Quote__c/a0p610000040iumAAA"
},
"Id": "a0p610000040iumAAA",
"Name": "Q-00880"
},
"nextKey": 5,
"netTotal": 300,
"netNonSegmentTotal": 300,
"lineItems": [
{
"record": {
"attributes": {
"type": "SBQQ__QuoteLine__c",
"url":
"/services/data/v41.0/sobjects/SBQQ__QuoteLine__c/a0l61000003u09UAAQ"
},
"Id": "a0l61000003u09UAAQ"
}
}
"lineItemGroups": [ ]
}]
47
Salesforce CPQ Developer Guide Generate Quote Document API
Apex Examples
Before saving the ContractRenewer example class, ensure that you've created individual Apex classes for your CPQ models.
// Define a class to hold information about the contracts to renew
private with sharing class CreateRenewalContext {
public Id masterContractId;
public Contract[] renewedContracts;
public Boolean returnOnlyQuoteId;
}
//define a class to hold the serialized context and the returned quote information
public with sharing class ContractRenewer {
public QuoteModel[] load(String masterContractId, String serializedContext) {
String quotesJSON =
SBQQ.ServiceRouter.load('SBQQ.ContractManipulationAPI.ContractRenewer', masterContractId,
serializedContext);
return (QuoteModel[]) JSON.deserialize(quotesJSON, List<QuoteModel>.class);
}
}
{"attributes":{"type":"SBQQ__Quote__c","url":"/services/data/v50.0/sobjects/SBQQ__Quote__c/123456"},"Id":"56789"}
48
Salesforce CPQ Developer Guide Generate Quote Document API
Formats
JSON, Apex
HTTP Method
POST
Authentication
Authorization: Bearer token
Request
Table 1: Parameters
Name Type Required Definition
Name String No The document name
Response
Table 2: Parameters
Name Type Description
jobID ID Apex queueable job ID
REST Examples
curl
"https://yourInstance.salesforce.com/services/apexrest/SBQQ/ServiceRouter?saver=QuoteDocumentAPI.SaveProposal"
Example request body data.json file for generating and saving a quote document.
"{\"saver\":\"SBQQ.QuoteDocumentAPI.Save\",\"model\":\"{\\\"name\\\":\\\"test\\\",\\\"quoteId\\\"
:\\\"a0n0R000000jhVC\\\",\\\"templateId\\\":\\\"a0l0R000000vahe\\\",\\\"outputFormat\\\":
\\\"PDF\\\",\\\"language\\\":\\\"en_US\\\",\\\"paperSize\\\":\\\"Default\\\"}\"}"
Example response body after creating APEX job for creating the quote document.
"7070R00000Nj8mjQAB"
49
Salesforce CPQ Developer Guide Service Router
APEX Examples
Before saving the GenerateQuoteProposal example class, make sure that the CPQ model classes are added as individual APEX classes in
your org.
public with sharing class GenerateQuoteProposal {
Run the following code in anonymous Apex to get Apex job ID for generating and saving the quote proposal.
QuoteProposalModel model = new QuoteProposalModel();
model.quoteId = 'a0n0R000000jhVC';
model.templateId = 'a0l0R000000vahe';
GenerateQuoteProposal proposalGenerator = new GenerateQuoteProposal();
String jobId = proposalGenerator.save(model);
System.debug(jobId);
Note:
• Attachments marked Required are ignored when you’re using the API. In contrast, when you’re using the Preview and Generate
document buttons, the attachments are automatically generated as part of the document.
• An attachment in the Template section is always included regardless of whether it’s marked Required. This behavior is also
observed when you’re using Preview and Generate document buttons.
• Guest users can’t create quote documents in the Documents folder. See Salesforce Help and SOAP API Developer Guide for details.
SEE ALSO:
Salesforce Help: Guest User Security Policies and Timelines
SOAP API Developer Guide: Folder
Service Router
SBQQ.ServiceRouter is a global Apex class serving as a single entry point for all API calls. You can
EDITIONS
use it for calls made by Apex code, Visualforce Remoting, or REST callouts.
SBQQ.ServiceRouter contains three global methods. Available in: Salesforce CPQ
Summer ’16 and later
• global static String read(String reader, String uid)
• global static String load(String loader, String uid, String context)
• global static String save(String saver, String model)
Each method accepts the name of a service provider, such as SBQQ.ProductAPI.ProductLoader as its first parameter. This lets Salesforce
CPQ route the API request to the appropriate internal handler. The internal handler isn’t global and can’t be called directly by code
outside the Salesforce CPQ package.
Use the read() method only when it needs a simple unique ID as input. For example, you could use read() when querying for a
quote from the database. Provide the quote’s ID as the request and, and read() returns the QuoteModel object.
Use the load() method when you need more input information than a simple unique ID, but don’t need to change anything in the
database. For example, you could use load() if you wanted to load products for a given currency code and pricebook ID. The load()
50
Salesforce CPQ Developer Guide CPQ API Quickstart Guide
method passes the unique ID as the second parameter. It then passes the extra information as a serialized JSON string in the third
parameter.
Use the save() method when you save a model to the database, such as when you save a quote. The save() method passes the
model as a serialized JSON string in the second parameter.
/**
* Note: this doesn’t perform a calculatation. Reference the calculate API to see how to
calculate a quote.
*/
//the Id of the pricebook for the quote and product being added
String pricebookId = '01sj0000003THhKAAW';
//the JSON formatted String representing the quote model to add a product to
String quoteModel = SBQQ.ServiceRouter.read('SBQQ.QuoteAPI.QuoteReader', quoteId);
//the JSON formatted String representing the product to be added to the quote
String productModel = SBQQ.ServiceRouter.load('SBQQ.ProductAPI.ProductLoader', productId,
'{"pricebookId" : "' + pricebookId + '", "currencyCode" : "' + currencyCode + '"}');
//the JSON formatted String representing the quote with the product added to it
String updatedQuoteModel = SBQQ.ServiceRouter.load('SBQQ.QuoteAPI.QuoteProductAdder', null,
'{"quote" : ' + quoteModel + ', "products" : [' + productModel + '], "ignoreCalculate" :
true}');
NODEJS
This example reads a quote, adds a product, calculates the quote, and saves it.
// 3rd party library to call into a Salesforce org
var jsforce = require('jsforce');
51
Salesforce CPQ Developer Guide CPQ API Quickstart Guide
// log in to the org with with a valid username and password using jsforce
var conn = new jsforce.Connection({loginUrl: loginUrl});
conn.login(username, password).then(function () {
return Promise.resolve(conn);
})
.then(function (conn) {
// read both the quote and the product to add
var quotePromise =
conn.apex.get('/SBQQ/ServiceRouter?reader=SBQQ.QuoteAPI.QuoteReader&uid=' + quoteId);
var productPromise =
conn.apex.patch('/SBQQ/ServiceRouter?loader=SBQQ.ProductAPI.ProductLoader&uid=' + productId,
{
context: JSON.stringify({
pricebookId: pricebookId,
currencyCode: currencyCode
})
});
return Promise.all([quotePromise, productPromise]);
})
.then(function (models) {
// add the retrieved product to the retrieved quote in the first group
var quoteModel = JSON.parse(models[0]);
var productModel = JSON.parse(models[1]);
return conn.apex.patch('/SBQQ/ServiceRouter?loader=SBQQ.QuoteAPI.QuoteProductAdder',
{
context: JSON.stringify({
quote: quoteModel,
products: [productModel],
groupKey: 0,
ignoreCalculate: true
})
});
})
.then(function (quoteWithProduct) {
var quote = JSON.parse(quoteWithProduct);
// cacluate the quote with the added product
return conn.apex.patch('/SBQQ/ServiceRouter?loader=SBQQ.QuoteAPI.QuoteCalculator', {
context: JSON.stringify({
52
Salesforce CPQ Developer Guide Disable CPQ Triggers in Apex
quote: quote
})
});
})
.then(function (calculatedQuote) {
var quote = JSON.parse(calculatedQuote);
// save the calucated quote
return conn.apex.post('/SBQQ/ServiceRouter', {
saver: 'SBQQ.QuoteAPI.QuoteSaver',
model: JSON.stringify(quote)
});
})
.then(function (savedQuoted) {
// log the quote has been saved
console.log('Quote finished processing', savedQuoted);
});
Note: TriggerControl disables only triggers in CPQ and Billing and in the Service Cloud for CPQ package. Other triggers or Salesforce
logic, or your own triggers, validations, workflow rules, or processes, are unaffected.
Methods
global static void disable();
Disables built-in CPQ triggers within the current transaction.
global static void enable();
Enables built-in CPQ triggers if they had previously been disabled.
global static Boolean isEnabled()
Returns true if CPQ triggers are currently enabled. Otherwise, returns false.
Example:
SBQQ.TriggerControl.disable();
try {
// Do something simple and interesting without
// running triggers.
quote.MyStatus__c = ‘Red’;
update quote;
} finally {
SBQQ.TriggerControl.enable();
}
53
Salesforce CPQ Developer Guide Advanced Approvals API
Example:
if (SBQQ.TriggerControl.isEnabled()) {
// Only run our logic if CPQ trigger logic is also enabled.
myRelatedObject.Quote__c = quote.Id;
insert myRelatedObject;
}
Approval API
Call the Advanced Approvals approval resource from an outside source.
EDITIONS
Invoke the approval API using the following service router call, replacing class with your class
name and method with your method name. Available in: Advanced
Approvals Spring '21 and
ServiceRouter?saver=AA.{class}.{method}
later
Use the following endpoint.
/services/apexrest/sbaa/ServiceRouter
The approval service accepts the following parameters.
Sample Request
Include a saver in the request body model. When you send the approval request, the CPQ service router evaluates the model and finds
the saver attribute. It then takes the value of the saver attribute - in this case, Approve - and maps that to the corresponding Advanced
Approvals Apex class.
Header
Content type: application/json
Authorization: Bearer [Access token or session ID]
54
Salesforce CPQ Developer Guide Advanced Approvals API
Body
{
"model":
"{\"approvalId\":\"a4H7Y000001makkUAA\",\"comments\":\"I approve!\"}",
"saver":"SBAA.ApprovalRestApiProvider.Approve"
}
Example: This example shows a basic JavaScript function for calling the Approval Service API from Google Sheets.
function reject() {
var sheet = SpreadsheetApp.getActiveSheet();
var data = sheet.getDataRange().getValues();
// Make a POST request with a JSON payload.
var model = {
"approvalId": data[1][0],
"comments": data[1][1]
};
var data = {
'saver': 'SBAA.ApprovalRestApiProvider.Approve',
'model': JSON.stringify(model)
};
var header = {
'authorization' : 'Bearer 00Dx0000000IiXXXXX.IshlpUqRUQo3FXXXXXXXXXXXXX'
};
var options = {
'method' : 'post',
'contentType': 'application/json',
'headers': header,
'muteHttpExceptions': false,
// Convert the JavaScript object to a JSON string.
'payload' : JSON.stringify(data)
};
var response = UrlFetchApp.fetch('https://server/services/apexrest/SBAA/ServiceRouter',
options);
var responseText = response.getContentText();
55
Salesforce CPQ Developer Guide Advanced Approvals API
Sample Request
Include a saver in the request body model. When you send the approval request, the CPQ service router evaluates the model and finds
the saver attribute. It then takes the value of the saver attribute - in this case, Reject - and maps that to the corresponding Advanced
Approvals Apex class.
Header
Content type: application/json
Authorization: Bearer [Access token or session ID]
Body
model:{
approvalId: “a1Sx000000000gF”,
comments: “ok then"},
saver: "SBAA.ApprovalRestApiProvider.Reject"
}
Example: This example shows a basic Javscript function for calling the Reject Service API from Google Sheets.
function reject() {
var sheet = SpreadsheetApp.getActiveSheet();
var data = sheet.getDataRange().getValues();
// Make a POST request with a JSON payload.
56
Salesforce CPQ Developer Guide Salesforce CPQ Plugins
var model = {
"approvalId": data[1][0],
"comments": data[1][1]
};
var data = {
'saver': 'SBAA.ApprovalRestApiProvider.Reject',
'model': JSON.stringify(model)
};
var header = {
'authorization' : 'Bearer
00Dx0000000IiSD!ARoAQAiD7e.IshlpUqRUQo3Fu6MSox3y1ToMNdEl8MqXXXXXXXXXXXX'
};
var options = {
'method' : 'post',
'contentType': 'application/json',
'headers': header,
'muteHttpExceptions': false,
// Convert the JavaScript object to a JSON string.
'payload' : JSON.stringify(data)
};
var response = UrlFetchApp.fetch('server/services/apexrest/SBAA/ServiceRouter',
options);
var responseText = response.getContentText();
57
Salesforce CPQ Developer Guide Javascript Quote Calculator Plugin
58
Salesforce CPQ Developer Guide Javascript Quote Calculator Plugin
JSForce
JSForce is a third-party library that provides a unified way to perform queries, execute Apex REST calls, use theMetadata API, or make
HTTP requests remotely. Methods access jsforce through the optional parameter conn.
59
Salesforce CPQ Developer Guide Javascript Quote Calculator Plugin
Note:
• The JSQCP is an ES6 module. It is transpiled via Babel and module-scoped by default. You can use any elements of the ES6
language or syntax. However, the plugin must be able to run in both browser and node environments. Global browser variables
such as window may not be available.
• With plugins, callouts (requests) to non-Salesforce endpoints aren’t supported for asynchronous calculations. For example,
requestGet fails in asynchronous calculations.
Field Availability
Javascript Quote Calculator plugins don't support custom fields on consumption rates and consumption schedules.
In general, Salesforce CPQ uses Salesforce API that's one version behind the newest Salesforce API.
For example, Salesforce Summer '21 uses Salesforce API version 52.0, so Salesforce CPQ Summer '21 uses Salesforce API version 51.0.
If you need to reference entities or fields Salesforce API version that's newer than what you're using in Salesforce CPQ, use the JSforce
property assignment conn.version='x';, replacing x with the version that you want to use. For example, the following method
shows how to overwrite the default API version to version 52.0.
export function onInit(quote, conn) {
conn.version = '52.0';
return conn.query("SELECT Name FROM ConsumptionSchedule")
.then(function (results) {
console.log(results);
return Promise.resolve();
})
}
onInit
The calculator calls this method before formula fields are evaluated. Returns {promise}.
export function onInit(quoteLineModels) {
return Promise.resolve();
};
60
Salesforce CPQ Developer Guide Javascript Quote Calculator Plugin
onBeforeCalculate
The calculator calls this method before calculation begins, but after formula fields have been evaluated. Returns {promise}.
export function onBeforeCalculate(quoteModel, quoteLineModels) {
return Promise.resolve();
};
onBeforePriceRules
The calculator calls this method before it evaluates price rules. Returns {promise}.
export function onBeforePriceRules(quoteModel, quoteLineModels) {
return Promise.resolve();
};
onAfterPriceRules
The calculator calls this method after it evaluates price rules. Returns {promise}.
export function onAfterPriceRules(quoteModel, quoteLineModels) {
return Promise.resolve();
};
61
Salesforce CPQ Developer Guide Javascript Quote Calculator Plugin
onAfterCalculate
The calculator calls this method after it completes a calculation, but before re-evaluating formula fields. Returns {promise}
export function onAfterCalculate(quoteModel, quoteLineModels) {
return Promise.resolve();
};
isFieldVisible
Note: This method can’t be used to alter data.
The calculator calls this method after it completes a calculation. Returns {Boolean}
if (fieldName == 'SBQQ__Description__c') {
return false;
}
return true;
};
isFieldEditable
Note: This method can’t be used to alter data.
62
Salesforce CPQ Developer Guide Javascript Quote Calculator Plugin
The calculator calls this method after it completes a calculation. Returns {Boolean}
if (fieldName == 'SBQQ__Description__c') {
return false;
}
return true;
};
quote.record["True_Effective_Term__c"] = maxEffectiveTerm;
}
return Promise.resolve()
63
Salesforce CPQ Developer Guide Javascript Quote Calculator Plugin
ed.setUTCDate(ed.getUTCDate() - 1);
}
return ed;
}
/**
* Takes a JS Date object and turns it into a string of the type 'YYYY-MM-DD', which
is what Apex is expecting.
* @param {Date} date The date to be stringified
* @returns {string}
*/
function toApexDate(/*Date*/ date) {
if (date == null) {
return null;
}
// Get the ISO formatted date string.
// This will be formatted: YYYY-MM-DDTHH:mm:ss.sssZ
var dateIso = date.toISOString();
64
Salesforce CPQ Developer Guide Javascript Quote Calculator Plugin
Note: The sample script assumes the Salesforce admin created a custom field Component
Custom Total on the Quote Line object.
Javascript
export function onInit(lines) {
if (lines != null) {
lines.forEach(function (line) {
line.record["Component_Custom_Total__c"] = 0;
});
}
};
65
Salesforce CPQ Developer Guide Javascript Quote Calculator Plugin
parent.record["Component_Custom_Total__c"] = pComponentCustomTotal;
}
});
}
};
66
Salesforce CPQ Developer Guide Javascript Quote Calculator Plugin
Javascript
67
Salesforce CPQ Developer Guide Javascript Quote Calculator Plugin
Insert Records
The sample JavaScript script can be used in the Quote Line Calculator to insert records.
EDITIONS
68
Salesforce CPQ Developer Guide Javascript Quote Calculator Plugin
This sample JavaSciprt code exports all of the methods that the calculator looks for, and documents their parameters and return types.
69
Salesforce CPQ Developer Guide Javascript Quote Calculator Plugin
Note:
• Salesforce CPQ prioritizes field-level security over page security plugins. If a field is read-only and an editability function for
that field returns True, the field remains read-only.
• Use the page security plugin only for hiding, showing, and adjusting the editability of fields. If you want change field values,
use the Javascript Quote Calculator Plugin.
• The quote line editor shows blank empty spaces for quote line drawer fields hidden by the page security plugin. To remove
these spaces, go to Salesforce CPQ line editor package settings and select Enable Compact Mode.
To create a page security plugin, define your code in a custom script record and then reference that record's name in the Quote Calculator
Plugin field within Salesforce CPQ Plugin package settings. If you’re already using a quote calculator plugin in that field, you can add
your page security plugin code to the calculator plugin’s custom script record.
70
Salesforce CPQ Developer Guide Javascript Quote Calculator Plugin
We strongly recommend that users on Salesforce CPQ Summer '19 and later use the new functions given their improved flexibility. If
your plugin uses pre-Summer '19 functions with isFieldEditableForObject or isFieldVisibleForObject functions
that use the line parameter, Salesforce CPQ ignores the new functions and uses the old functions instead.
71
Salesforce CPQ Developer Guide Javascript Quote Calculator Plugin
To specify whether your changes apply to a field on the quote or on the quote line, use an if statement for your objectName in
the isFieldVisibleForObject or isFieldEditableForObject code block. For example, in the following code
segment, we're targeting the Markup Rate field on the quote.
export function isFieldEditableForObject(fieldName, quoteOrLine, conn, objectName){
if (objectName === 'Quote__c' && fieldName === 'SBQQ__MarkupRate__c')
However, the following code segment targets Markup Rate on both the quote and the quote line.
export function isFieldEditableForObject(fieldName, quoteOrLine, conn, objectName){
if fieldName === 'SBQQ__MarkupRate__c'
Example: In this example, if a quote's Customer Discount is greater than 10%, we lock the quote's Markup Rate field from edits.
export function isFieldEditableForObject(fieldName, quoteOrLine, conn, objectName){
if (objectName === 'Quote__c' && fieldName === 'SBQQ__MarkupRate__c') {
if (quoteOrLine.SBQQ__CustomerDiscount__c > 10) {
return false;
}
}
}
Example: In this example, if a quote line's Distributor Discount is greater than 10%, we hide the quote line's Markup Rate field.
export function isFieldVisibleForObject(fieldName, quoteOrline, conn, objectName){
if (objectName === 'QuoteLine__c' && fieldName === 'SBQQ__MarkupRate__c') {
if (quoteOrLine.SBQQ__CustomerDiscount__c > 10) {
return false;
}
}
}
Example: One function can also evaluate and act on quote and quote line fields at the same time, including twin fields. In this
example, if a quote's Customer Discount is greater than 10%, we lock the quote's Markup Rate field from edits. If the quote line's
Distributor Discount is greater than 10%, we hide the quote line's Markup Rate field.
Example:
export function isFieldEditableForObject(fieldName, quoteOrLine, conn, objectName){
if (objectName === 'Quote__c' && fieldName === 'SBQQ__MarkupRate__c') {
if (quoteOrLine.SBQQ__CustomerDiscount__c > 10) {
return false;
}
}
return false;
}
}
}
72
Salesforce CPQ Developer Guide Javascript Quote Calculator Plugin
Note: Salesforce CPQ has deprecated support for Apex page security plugins. Review Available in: All Salesforce
Javascript Page Security Plugin for information on the currently-supported version. CPQ Editions
The Legacy Page Security Plugin handles two types of use cases.
Show or hide fields on each quote line
For example, you’re selling training classes and you want to capture how many students are participating in the class. Use the page
security plugin to hide a student number field.
Make quote line fields read-only or writable
For example, you allow your users to specify the subscription term on each quote line, but you have some products that can only
be quoted on a 12-month basis. Use the page security plugin to make the Subscription Term field read-only for such products, while
keeping it writable for the other products.
To use the Legacy Page Security Plugin, first create an Apex class. Then enter the Apex class name in the Legacy Page Security Plugin
setting in the Salesforce CPQ package settings. You can call only one Apex class at a time in the Legacy Page Security Plugin.
Example:
global class MyPageSecurityPlugin implements SBQQ.PageSecurityPlugin2 {
public Boolean isFieldEditable(String pageName, Schema.SObjectField field) {
return null;
}
73
Salesforce CPQ Developer Guide Product Search Plugin
• Quote calculator plugins perform synchronous calculations in the quote line editor UI, within a standard web browser with all
expected platform and browser information available. However, asynchronous calculations occur within a Heroku application outside
of the web browser. If your plugin must reference the state of the platform running the calculation, make sure to account for whether
the quote line editor or Heroku is handling the calculation.
• If your plugin makes callouts to an endpoint that you own, make sure that both the local Salesforce host and your external Heroku
host can access the endpoint URI.
• The total time for a calculation plus the time for a callout to Heroku from your system can’t be longer than 30 seconds. Otherwise,
Heroku will terminate the calculation.
Namespace
SBQQ
Usage
For example, in Product Search, you could configure the plugin to return all search results in descending order from the most recent
Last Ordered Date. If a sales rep enters "Tablets," the search results show tablets starting from the most recent Last Ordered Date field
value. Users can then further filter through the Product Search filter panel, if necessary.
Product search plugins can use only a subset of CPQ quote fields by default. If you can't pass a field to your product search, or if it passes
as null, you must instead pull it with a SOQL query using the ID passed with the quote model.
74
Salesforce CPQ Developer Guide Product Search Plugin
* 2.1 getFilterDefaultValue()
* }
* 3.0 isSearchCustom (CUSTOM vs ENHANCED)
* IF(isCustom){
* 4.0 search()
* }
* ELSE{
* 4.0 getAdditionalSearchFilters()
* }
1. The Constructor can be called first, but it’s not required for implementation.
2. Salesforce CPQ calls the following two methods for each search input.
• isFilterHidden: Determines whether to hide the search input from the quote line editor
• getFilterDefaultValue: Sets the field value for the initial search
3. Salesforce CPQ calls isSearchCustom to determine whether you’re using Custom or Enhanced searching.
4. If isSearchCustom returned True, Salesforce CPQ calls search(). This method gives you full control of the search query - you’ll build
the Select Clause and Where Clause manually, then build and perform the query.
5. If isSearchCustom returned False, Salesforce CPQ calls getAdditionalSearchFilters. This method appends a WHERE clause to the
existing SOQL query.
getAdditionalSearchFilters(quote, fieldValuesMap)
Appends a WHERE clause to the SOQL query used for the product search, so that you can further refine a user's search input. Salesforce
CPQ calls this method only when isSearchCustom returns FALSE.
getFilterDefaultValue(quote, fieldName)
Determines the value for the initial search. Salesforce CPQ calls this implemented method for each input field.
isFilterHidden(quote, fieldName)
Determines the visibility of a filter in the UI. Return True to hide the filter and False to let users see the filter. Salesforce CPQ
calls this implemented method for each search input field.
isSearchCustom(quote, fieldValuesMap)
Called after isFilterHidden and getFilterDefaulValue. Returns True if the plugin uses custom searching or
False if the plugin uses enhanced searching.
search(quote, fieldValuesMap)
Overrides the entire user search input. Salesforce CPQ calls this method only when isSearchCustom returns TRUE.
getAdditionalSearchFilters(quote, fieldValuesMap)
Appends a WHERE clause to the SOQL query used for the product search, so that you can further refine a user's search input. Salesforce
CPQ calls this method only when isSearchCustom returns FALSE.
75
Salesforce CPQ Developer Guide Product Search Plugin
Signature
global String getAdditionalSearchFilters(SObject quote, Map<String,Object>
fieldValuesMap)
Parameters
quote
Type: SObject
The current quote.
fieldValuesMap
Type: Map<String,Object>
A map of the search criteria. The Key is a Product2 API name and the value is the desired search value.
Return Value
Type: String
The additional search filter, as a SOQL query formatted as a string. For example, 'AND Product2.Inventory_Level__c >
3'
Example
In this method, we take an existing filter for products in a Hardware family, and append an additional filter for inventory levels greater
than 3.
global String getAdditionalSearchFilters(SObject quote, Map<String, Object> fieldValuesMap)
{
String additionalFilter = NULL;
if(fieldValuesMap.get('Family') == 'Hardware') {
additionalFilter = 'AND Product2.Inventory_Level__c > 3';
}
return additionalFilter;
}
getFilterDefaultValue(quote, fieldName)
Determines the value for the initial search. Salesforce CPQ calls this implemented method for each input field.
Signature
global String getFilterDefaultValue(SObject quote, String fieldName)
Parameters
quote
Type: SObject
The current quote.
fieldName
Type: String
76
Salesforce CPQ Developer Guide Product Search Plugin
Return Value
Type: String
Returns the string value used as the filter's initial search input.
Example
In this example, the method sets the product family filter's value to Service if the quote has a type of Quote.
global String getFilterDefaultValue(SObject quote, String fieldName) {
// This would set Product Family filter to Service if Quote Type is Quote
return (fieldName == 'Family' && quote.SBQQ__Type__c. == 'Quote') ? 'Service' : null;
}
isFilterHidden(quote, fieldName)
Determines the visibility of a filter in the UI. Return True to hide the filter and False to let users see the filter. Salesforce CPQ calls
this implemented method for each search input field.
Signature
global Boolean isFilterHidden(SObject quote, String fieldName)
Parameters
quote
Type: SObject
The quote object containing the field used to determine whether the method returns true or false.
fieldName
Type: String
The field tested to determine whether the method returns true or false.
Return Value
Type: Boolean
Return True to hide the filter and False to let users see the filter.
Example
This example shows a method that returns True and hides the filter if the quote's status has a value of Approved.
global Boolean isFilterHidden(SObject quote, String fieldName) {
// This would hide Product Code filter if Quote Status is Approved
return fieldName == 'ProductCode' && quote.SBQQ__Status__c. == 'Approved';
}
77
Salesforce CPQ Developer Guide Product Search Plugin
isSearchCustom(quote, fieldValuesMap)
Called after isFilterHidden and getFilterDefaulValue. Returns True if the plugin uses custom searching or False
if the plugin uses enhanced searching.
Signature
global Boolean isSearchCustom(SObject quote, Map<String,Object> fieldValuesMap)
Parameters
quote
Type: SObject
The current quote.
fieldValuesMap
Type: Map<String,Object>
A map of the search criteria. The map key is a Product2 API name and the value is the desired search value.
Return Value
Type: Boolean
Return True to use custom searching or False to use enhanced searching.
If you use custom searching, Salesforce CPQ calls search for search execution. The search() method lets you build the SOQL
query's SELECT and WHERE clauses manually before you perform your query.
If you use enhanced searching, Salesforce CPQ calls getAdditionalSearchFilters for search execution. The
getAdditionalSearchFilters method appends a WHERE clause to the existing SOQL query.
Example
In this example, we want a method that returns True if the original search criteria defined and used a Search field for sorting.
global Boolean isSearchCustom(SObject quote, Map<String,Object> fieldValuesMap) {
// This would use CUSTOM mode if a Search field for sorting was defined and used
return fieldValuesMap.get('Sort_By__c') != '';
}
search(quote, fieldValuesMap)
Overrides the entire user search input. Salesforce CPQ calls this method only when isSearchCustom returns TRUE.
Signature
global List<PricebookEntry> search(SObject quote, Map<String,Object> fieldValuesMap)
Parameters
quote
Type: SObject
The current quote.
78
Salesforce CPQ Developer Guide Product Search Plugin
fieldValuesMap
Type: Map<String,Object>
A map of the search criteria. The map key is a Product2 API name and the value is the desired search value. Contains only keys for
non-null values.
Return Value
Type: List<PricebookEntry>
Example
This example builds and returns a list of price book entries.
global List<PricebookEntry> search(SObject quote, Map<String,Object> fieldValuesMap){
// Get all possible filter fields from the search filter field set
List<Schema.FieldSetMember> searchFilterFieldSetFields =
SObjectType.Product2.FieldSets.SBQQ__SearchFilters.getFields();
// Get all possible fields from the search result field set
List<Schema.FieldSetMember> searchResultFieldSetFields =
SObjectType.Product2.FieldSets.SBQQ__SearchResults.getFields();
// Build the Select string
String selectClause = 'SELECT ';
for(Schema.FieldSetMember field : searchResultFieldSetFields) {
selectClause += 'Product2.' + field.getFieldPath() + ', ';
}
selectClause += 'Id, UnitPrice, Pricebook2Id, Product2Id, Product2.Id';
// Build the Where clause
String whereClause = '';
for(Schema.FieldSetMember field : searchFilterFieldSetFields) {
if(!fieldValuesMap.containsKey(field.getFieldPath())) {
continue;
}
if(field.getType() == Schema.DisplayType.String || field.getType() ==
Schema.DisplayType.Picklist) {
whereClause += 'Product2.' + field.getFieldPath() + ' LIKE \'%' +
fieldValuesMap.get(field.getFieldPath()) + '%\' AND ';
}
}
whereClause += 'Pricebook2Id = \'' + quote.get('SBQQ__Pricebook__c') + '\'';
// Build the query
String query = selectClause + ' FROM PricebookEntry WHERE ' + whereClause;
// Perform the query
List<PricebookEntry> pbes = new List<PricebookEntry>();
pbes = Database.query(query);
return pbes;
}
79
Salesforce CPQ Developer Guide Product Search Plugin
Namespace
SBQQ
Usage
You can configure the Product Search plugin to filter a guided selling prompt based on certain parameters when users enter a value.
For example, in a guided selling prompt, you could configure the plugin to return all search results in descending order from the most
recent Last Ordered Date. When the user chooses their input, the products returned in the search results are shown starting from the
most recent Last Ordered Date field value.
Product search plugins can use only a subset of CPQ quote fields by default. If you can't pass a field to your guided selling input, or if it
passes as null, you must retrieve it with a SOQL query.
Order of Execution
For a Guided Selling prompt, Salesforce CPQ executes the implemented SBQQ.ProductSearchPlugin methods in the following order.
//**The constructor is optional**//
* 1.0 Constructor()
* 2.0 FOREACH(Search Field){
* 2.1 isInputHidden()
* 2.1 getInputDefaultValue()
* }
* 3.0 isSuggestCustom (CUSTOM vs ENHANCED)
* IF(isCustom){
* 4.0 suggest()
* }
* ELSE{
80
Salesforce CPQ Developer Guide Product Search Plugin
* 4.0 getAdditionalSuggestFilters()
* }
3. Salesforce CPQ calls isSuggestCustom to determine whether you’re using custom or enhanced searching.
4. If isInputCustom returned TRUE, Salesforce CPQ calls suggest. This method gives you full control of the search query - you’ll
build the SELECT Clause and WHERE Clause manually, then build and perform the query.
5. If isInputCustom returned FALSE, Salesforce CPQ calls getAdditionalSuggestFilters. This method appends a
WHERE clause to the existing SOQL query.
getAdditionalSuggestFilters(quote, fieldValuesMap)
Appends a WHERE clause to the SOQL query used for a guided selling prompt. Salesforce CPQ Calls this method only when
isSuggestCustom returns FALSE.
getInputDefaultValue(quote, fieldName)
Determines the input for the initial guided selling prompt.
isInputHidden(quote, fieldName)
Determines the visibility of an input in the Guided Selling UI. Return True to hide the input and False to let users see the input.
Salesforce CPQ calls this method for each input.
isSuggestCustom(quote, fieldValuesMap)
Called after isInputHidden and getInputDefaulValue. Returns True for Salesforce CPQ to use Custom searching or
False for Salesforce CPQ to use Enhanced searching.
suggest(quote, fieldValuesMap)
Overrides the user suggestion input. Salesforce CPQ calls this method only when isSuggestCustom returns TRUE.
getAdditionalSuggestFilters(quote, fieldValuesMap)
Appends a WHERE clause to the SOQL query used for a guided selling prompt. Salesforce CPQ Calls this method only when
isSuggestCustom returns FALSE.
Signature
global String getAdditionalSuggestFilters(SObject quote, Map<String,Object>
fieldValuesMap)
81
Salesforce CPQ Developer Guide Product Search Plugin
Parameters
quote
Type: SObject
The current quote.
fieldValuesMap
Type: Map<String,Object>
A map of the guided selling suggestion criteria. The Key is a Product2 API name and the value is the desired suggest value.
Return Value
Type: String
The additional suggestion filter, as a WHERE clause. For example, 'AND Product2.Inventory_Level__c > 3'
Example
global String getAdditionalSuggestFilters(SObject quote, Map<String, Object>
inputValuesMap) {
System.debug('METHOD CALLED: getAdditionalSuggestFilters');
/**Adds an inventory check in an input = 'Yes' for an urgent shipment**/
String additionalFilter = NULL;
String isUrgent = 'No'
if(inputValuesMap.containsKey('Urgent Shipment')){
isUrgent = (String) inputValuesMap.get('Urgent Shipment');
}
if(isUrgent == 'Yes'){
additionalFilter = 'AND Product2.Inventory_Level__c > 3';
}
return additionalFilter;
}
getInputDefaultValue(quote, fieldName)
Determines the input for the initial guided selling prompt.
Signature
global String getInputDefaultValue(SObject quote, String fieldName)
Parameters
quote
Type: SObject
The current quote.
fieldName
Type: String
Quote field used in evaluations to determine the method's output.
82
Salesforce CPQ Developer Guide Product Search Plugin
Return Value
Type: String
Returns the string value used as the guided selling prompt's initial input.
isInputHidden(quote, fieldName)
Determines the visibility of an input in the Guided Selling UI. Return True to hide the input and False to let users see the input.
Salesforce CPQ calls this method for each input.
Signature
global Boolean isInputHidden(SObject quote, String fieldName)
Parameters
quote
Type: SObject
The current quote.
fieldName
Type: String
The field tested to determine whether the method returns true or false.
Return Value
Type: Boolean
Return True to hide the input and False to let users see the input.
Example
This example hides an input called "Urgent Shipment" on Fridays.
global Boolean isInputHidden(SObject quote, String input){
/**Hides an input called 'Urgent Shipment' on Fridays**/
return input == 'Urgent Shipment' && Datetime.now().format('F') == 5;
}
isSuggestCustom(quote, fieldValuesMap)
Called after isInputHidden and getInputDefaulValue. Returns True for Salesforce CPQ to use Custom searching or
False for Salesforce CPQ to use Enhanced searching.
Signature
global boolean isSuggestCustom(SObject quote, Map<String,Object> fieldValuesMap)
Parameters
quote
Type: SObject
83
Salesforce CPQ Developer Guide Product Search Plugin
Return Value
Type: Boolean
Return True to use Custom searching or False to use Enhanced searching.
If you use Custom searching, Salesforce CPQ calls search for search execution. The search() method lets you build the SOQL
query's SELECT and WHERE clauses manually before you perform your query.
If you use Enhanced searching, Salesforce CPQ calls getAdditionalSearchFilters for search execution. The
getAdditionalSearchFilters method appends a WHERE clause to the existing SOQL query.
suggest(quote, fieldValuesMap)
Overrides the user suggestion input. Salesforce CPQ calls this method only when isSuggestCustom returns TRUE.
Signature
global List<PricebookEntry> suggest(SObject quote, Map<String,Object> fieldValuesMap)
Parameters
quote
Type: SObject
The current quote.
fieldValuesMap
Type: Map<String,Object>
A map of the search criteria. The map key is a Product2 API name and the value is the desired search value. Contains only keys for
non-null values.
Return Value
Type: List<PricebookEntry>
Example
/**
* When Using Guided Selling in CUSTOM mode, Over-Ride entire search
* Product2 Fields in the Search Results Field Set should be Set.
*/
global List<PricebookEntry> suggest(SObject quote, Map<String, Object> inputValuesMap)
{
System.debug('METHOD CALLED: suggest');
//GET ALL POSSIBLE FIELDS FROM THE SEARCH RESULTS FIELD SET
List<Schema.FieldSetMember> searchResultFieldSetFields =
SObjectType.Product2.fieldSets.SBQQ__SearchResults.getFields();
84
Salesforce CPQ Developer Guide Product Search Plugin
return pbes;
}
}
85
Salesforce CPQ Developer Guide Recommended Products Plugin
This method takes quote and quote lines as arguments, and it outputs an ordered list of recommended price book entries. If at runtime
the plugin input is missing a field required for your implementation, add it to the ReferencedFields field set on the corresponding
object.
Add your plugin’s class name on the Plugins tab in Settings.
Note:
• A maximum of 2,000 price book entries are shown on the Recommended Products page, similar to the limit on the Product
Lookup page. Your implementation class can return up to your top 2,000 recommendations. If you have more, you can use a
recommendation score to sort and choose your top 2,000 products.
• The Recommended Products plugin doesn’t support the Large Quote Threshold setting.
86
Salesforce CPQ Developer Guide Recommended Products Plugin
• Salesforce CPQ prioritizes field-level security over Recommended Product plugins. If your plugin includes fields that your users
don’t have permission to view, those fields aren't displayed on the Recommended Products page.
• The Product Recommendation page uses the same field set as the Product Lookup page.
Walkthrough
1. Add products to a quote and click the Add Recommendations custom action.
2. Salesforce calls your plugin implementation class and obtains an ordered list of PricebookEntry sObjects. These sObjects are then
displayed on the Recommended Products page.
Methods
recommend()
Description
Returns the product recommendations.
Parameters
Return Values
PricebookEntry[ ] : Ordered list of PricebookEntry SObjects.
Error Scenarios
If your plugin throws an exception, the error shows on the Recommendations Lookup page. To show that the plugin implementation
throws the error, the error message shows “Plugin Error:" as a prefix followed by the message from the exception.
87
Salesforce CPQ Developer Guide Recommended Products Plugin
Sample Implementation
When you implement the Recommended Products plugin, you can create your own recommendation engine or use a third-party
recommendation service. Store the product recommendations in your org in a custom object. Then, query the recommendations in the
custom object from in the recommend() method of your plugin.
In this example, the name of the custom object that stores recommendations is ProductRecommendation__c.
// Create your own Custom Object to store your product recommendations
ProductRecommendation__c {
Id Product2Id__c,
Id RecommendedProduct2Id__c,
}
FROM PricebookEntry
WHERE Product2Id IN :recommendedProductIds AND Pricebook2Id = :pricebookId AND
CurrencyIsoCode=:quoteCurrency];
return priceBookEntries;
}
}
88
Salesforce CPQ Developer Guide External Configurator Plugins
Important: We strongly recommend that you choose Dialog Window for the value of URL Target. Replace Window causes users
to lose all their work when the external configurator loads.
89
Salesforce CPQ Developer Guide External Configurator Plugins
2. Use the easyXDM.RPC constructor with the following configuration. Set the configuration’s keys to postMessage.
var rpc = new easyXDM.Rpc({},{
remote: {
postMessage: {} // This method is defined in SteelBrick
},
local: {
postMessage: function(message) {
// Do something with the JSON string that is received from SteelBrick.
}
}
});
3. After configuring the JSON, use Salesforce CPQ’s postMessage method to send the JSON string back to the Salesforce CPQ app.
rpc.postMessage(JSON-string);
4. To create a cancel button, use the Salesforce CPQ postMessage method to send the value null back to the Salesforce CPQ
app.
rpc.postMessage(null);
90
Salesforce CPQ Developer Guide Legacy Quote Calculator Plugin
Note: Salesforce CPQ no longer provides support for Legacy Quote Calculator plugins. Check Available in: Salesforce CPQ
out the Javascript Quote Calculator Plugin for support and improved features. Winter ’16 and later
Note: The sample script assumes the Salesforce admin created custom fields True
Effective End Date and True Effective Term on the Quote Line object.
Example:
global class QCPWinter16Legacy2 implements SBQQ.QuoteCalculatorPlugin,
SBQQ.QuoteCalculatorPlugin2 {
/* This QCP examples calculates and stores the effective end date on each quote line,
as well as the effective term.
It also stores the max(effective end date) and max(effective term) on the Quote
object
*/
91
Salesforce CPQ Developer Guide Legacy Quote Calculator Plugin
by the plugin and not in the Line Editor field set on the Quote Line
object
String.valueOf(SBQQ__QuoteLine__c.My_Field_API_Name__c)
*/
String.valueOf(SBQQ__QuoteLine__c.True_Effective_End_Date__c),
String.valueOf(SBQQ__QuoteLine__c.True_Effective_Term__c),
String.valueOf(SBQQ__Quote__c.True_Effective_End_Date__c),
String.valueOf(SBQQ__Quote__c.True_Effective_Term__c),
String.valueOf(SBQQ__QuoteLine__c.SBQQ__EffectiveStartDate__c),
String.valueOf(SBQQ__QuoteLine__c.SBQQ__EffectiveEndDate__c),
String.valueOf(SBQQ__QuoteLine__c.SBQQ__SubscriptionTerm__c),
String.valueOf(SBQQ__QuoteLine__c.SBQQ__DefaultSubscriptionTerm__c),
String.valueOf(SBQQ__Quote__c.SBQQ__SubscriptionTerm__c)
};
}
92
Salesforce CPQ Developer Guide Legacy Quote Calculator Plugin
}
}
}
return lineTerm;
}
93
Salesforce CPQ Developer Guide Legacy Quote Calculator Plugin
Note: Salesforce CPQ no longer provides support for Legacy Quote Calculator plugins. Check Available in: Salesforce CPQ
out the Javascript Quote Calculator Plugin for support and improved features. Winter ’16 and later
Note: The sample script assumes the Salesforce admin created a custom field Component
Custom Total on the Quote Line object.
Example:
global class QCPWinter16Legacy implements SBQQ.QuoteCalculatorPlugin,
SBQQ.QuoteCalculatorPlugin2 {
by the plugin and not in the Line Editor field set on the Quote Line
object
String.valueOf(SBQQ__QuoteLine__c.My_Field_API_Name__c)
*/
String.valueOf(SBQQ__QuoteLine__c.Component_Custom_Total__c),
String.valueOf(SBQQ__QuoteLine__c.SBQQ__ProratedListPrice__c),
String.valueOf(SBQQ__QuoteLine__c.SBQQ__PriorQuantity__c),
String.valueOf(SBQQ__QuoteLine__c.SBQQ__PricingMethod__c),
String.valueOf(SBQQ__QuoteLine__c.SBQQ__DiscountScheduleType__c),
String.valueOf(SBQQ__QuoteLine__c.SBQQ__Renewal__c),
String.valueOf(SBQQ__QuoteLine__c.SBQQ__Existing__c),
String.valueOf(SBQQ__QuoteLine__c.SBQQ__SubscriptionPricing__c)
};
}
94
Salesforce CPQ Developer Guide Legacy Quote Calculator Plugin
if(parent != null) {
Decimal pComponentCustomTotal =
(Decimal)parent.get(String.valueOf(SBQQ__QuoteLine__c.Component_Custom_Total__c));
Decimal cListPrice =
(Decimal)line.get(String.valueOf(SBQQ__QuoteLine__c.SBQQ__ProratedListPrice__c));
Decimal cQuantity =
(Decimal)line.get(String.valueOf(SBQQ__QuoteLine__c.SBQQ__Quantity__c));
Decimal cPriorQuantity =
(Decimal)line.get(String.valueOf(SBQQ__QuoteLine__c.SBQQ__PriorQuantity__c));
String cPricingMethod =
(String)line.get(String.valueOf(SBQQ__QuoteLine__c.SBQQ__PricingMethod__c));
String cDiscountScheduleType =
(String)line.get(String.valueOf(SBQQ__QuoteLine__c.SBQQ__DiscountScheduleType__c));
Boolean cRenewal =
(Boolean)line.get(String.valueOf(SBQQ__QuoteLine__c.SBQQ__Renewal__c));
Boolean cExisting =
(Boolean)line.get(String.valueOf(SBQQ__QuoteLine__c.SBQQ__Existing__c));
String cSubscriptionPricing =
(String)line.get(String.valueOf(SBQQ__QuoteLine__c.SBQQ__SubscriptionPricing__c));
parent.put(SBQQ__QuoteLine__c.Component_Custom_Total__c,
pComponentCustomTotal);
}
}
}
95
Salesforce CPQ Developer Guide Legacy Quote Calculator Plugin
line.put(SBQQ__QuoteLine__c.Component_Custom_Total__c, 0);
}
}
96
Salesforce CPQ Developer Guide Legacy Quote Calculator Plugin
result = 0;
} else {
if(existing == true && subscriptionPricing == 'Percent Of
Total' && listPrice != 0 && deltaQuantity >= 0) {
result = quantity;
} else {
if(existing == true) {
result = deltaQuantity;
} else {
result = quantity;
}
}
}
}
}
}
}
return result;
}
Note: Salesforce CPQ no longer provides support for Legacy Quote Calculator plugins. Check Available in: Salesforce CPQ
out the Javascript Quote Calculator Plugin for support and improved features. Winter ’16 and later
Example:
global class QCPForFindingLookupRecords implements
SBQQ.QuoteCalculatorPlugin, SBQQ.QuoteCalculatorPlugin2 {
global set<String> getReferencedFields() {
return new Set<String> {
String.valueOf(SBQQ__QuoteLine__c.SBQQ__ProductCode__c),
String.valueOf(SBQQ__QuoteLine__c.SBQQ__Description__c)
};
}
97
Salesforce CPQ Developer Guide Product Configuration Initializer for Guided Selling
public LF_ProductInitializerController() {
98
Salesforce CPQ Developer Guide Product Configuration Initializer for Guided Selling
99
Salesforce CPQ Developer Guide Product Search Executor for Guided Selling
<product id="{!product.Id}">
<apex:repeat var="opt" value="{!product.SBQQ__Options__r}">
<option id="{!opt.Id}"
selected="{!opt.SBQQ__Selected__c}"
quantity="{!ROUND(opt.SBQQ__Quantity__c, 0)}"/>
</apex:repeat>
</product>
</apex:repeat>
</products>
</apex:page>
Example: Your organization sells laptop workstations. A guided selling prompt lets sales reps filter your product catalog by
memory, screen size, and type of processor. You could also make a simple product search executor plugin that further filters their
results by active products and products that aren’t bundle components.
Here’s a sample APEX controller for your plugin.
public with sharing class TWProductSearchController {
public Product2[] products {get; set;}
public String error {get; set;}
public TWProductSearchController() {
products = [SELECT Id FROM Product2 WHERE IsActive = true AND SBQQ__Component__c
= false];
}
}
100
Salesforce CPQ Developer Guide Custom Action Plugin
101
Salesforce CPQ Developer Guide Salesforce CPQ Electronic Signature Plugin
To create a custom action plugin, create a custom script record and enter your code in the Code field. Then, go to Salesforce CPQ package
settings an open the plugins tab. Enter the name of your custom script in the Custom Action Plugin field and save your changes.
Here’s a basic template for the plugin, without any additional code. You can use onBeforeCloneLine or onAfterCloneLine as needed.
export function onBeforeCloneLine(quote, clonedLines) {
return Promise.resolve();
}
String getSendButtonLabel();
}
102
INDEX
A L
Add products 22–23, 28 Legacy quote calculator plugin 91, 94, 97
Amend contracts 42, 46, 50
Apex 73, 91, 94, 97, 100 O
Option model 5
C
Calculate API 16 P
Calculator plugin 60 Page security plugin 57, 70, 73
Configuration attribute model 7, 13 Plugin 57
Configuration model 8–9, 11 Pricing API 14
contracts 42 Product API 26
CPQ 2–16, 22–23, 26, 28, 30, 42, 46, 48, 50–51, 53, 89–90 Product model 10
CPQ apex 70, 73, 91, 94, 97, 100 Product search plugin 74
CPQ API 2–16, 26, 42, 46, 50–51, 53
CPQ API quickstart guide 2–13, 51, 53 Q
CPQ contracts 42 QCP 58–60, 63, 65, 67–68
CPQ plugin 57, 70, 73, 91, 94, 97, 100, 102 Quote API 15–16
CPQ plugins 74 Quote calculator plugin 57
Quote Calculator Plugin 58–59, 63, 65, 67–68
D Quote terms 30
Document API 12 QuoteProposal model 12
Document store plugin 100
S
E Salesforce calculator 60
Electronic signature plugin 57, 102 Salesforce CPQ 57–60, 63, 65, 67–68, 70, 73, 89–91, 94, 97, 100,
External configurator 89–90 102
Save API 15
F
Feature model 6 U
User Interface API quickstart 14, 20, 22–23, 28, 30, 42, 46, 48, 50
J
JSForce 68 W
JSQCP 58–60, 63, 65, 67–68 Web application 89–90
103