Flexible Business Logic in Salesforce CPQ using Javascript
Colin Campbell
Business Solutions Architect & Consultant | CRM, CPQ & Revenue Processes | Salesforce Partner | Mentor-Help to Grow | Business Owner
Salesforce CPQ [Configure, Price, Quote] is the backbone of Salesforce Revenue Cloud allowing businesses to build complex product quotes in a controlled and systematic fashion. For the sales user it provides a system to manage complex product configuration so the correct products are quoted for the correct customer requirement. And for the business it provides governance over pricing applying pricing structures and rules to ensure the price that is quoted is the right price conforming with company pricing strategy and policy.
Salesforce CPQ is designed to deliver all the above using no-code system configuration techniques. Product configurations can be defined and price structures enabled using out of the box point and click setup by a CPQ Administrator. Additional configurable tools are available to manage specific customer business logic. Examples of this are Summary Variables which can be used to calculate custom aggregate values such as sum totals of certain products which in turn can drive configurable Price Rules around discount values and the like.
However the no-code configuration approach has limitations and drawbacks. Complex business logic may be onerous to implement using the configuration techniques available. For example it may require many Summary Variables to be defined with complex interactions with a number of Price Rules. And some logic may be hard to achieve with the configuration options available .
Each of the configurations is also represented as a Salesforce data record. These records have to be deployed from development sandboxes to production and changes maintained in subsequent deployments which can be a significant overhead in complex configurations.
Additionally the Salesforce system closely monitors performance through preset governor limits to ensure the platform is robust and available. Limitations on configuration options are present and lengthy process times are prohibited through system controls such as timeouts. With a complex system such as CPQ these system limits can be commonly encountered.
Given the above limitations and impacts from the no-code configuration approach, Salesforce CPQ offers a number of plugin capabilities. One of these is the Javascript Quote Calculator Plugin (QCP). With the QCP Javascript can be written within a custom script record. This custom Javascript can read and write Quote and Quote Line variables and perform calculations from these. Other variables from related records to Quote and Quote Line can be directly referenced. Salesforce record queries can be performed and remote HTTP requests executed enabling interaction with the Salesforce database or 3rd party systems. Examples of the latter could include reaching out to a 3rd party ERP system for latest pricing or inventory information.
Because the business logic can now be written in Javascript it is a much more flexible environment than the no-code configuration environment. An example of this is finding the number of unique product categories within a quote. With Javascript this can be done by creating an array entry for each quote line product category and then assigning the array to a Javascript set which forces unique entries and then simply get the size of the set. This requires only a few lines of Javascript.
Once you are up and running with using the Javascript QCP then lots of examples typically appear where it makes sense to perform these within the QCP.
Changes to the QCP are deployed via a single custom script record update making deployments across Salesforce orgs easier than deploying many separate configuration data records.
From an architectural point of view Salesforce CPQ is designed to allow selection of external resources to perform designated functions ie use the best tool for the right job philosophy. CPQ itself uses an external service to run its calculations away from the core Salesforce platform. Other options available are to use an external configurator for more advanced configuration requirements. The QCP is an extension of this concept where selected logic load can be handled by the local Javascript capabilities of the browser.
领英推荐
One interesting aspect to the QCP is that many adopter of Salesforce CPQ are transitioning from quote spreadsheet calculators. Moving away from the likes of Excel to gain the benefits of a robust controlled central system for managing complex quoting. Many of these source spreadsheet calculators will have been built using scripting such as VBA or Javascript. So the quoting journey using CPQ and QCP may end up using a lot of the logic already built in these initial spreadsheets - which can be a bonus.
Full technical details of the QCP are available here.
Colin Campbell is a Salesforce Solution Architect and Consultant and has worked on over 40 Salesforce projects.
Salesforce, Odoo, Xero, Quickbooks, IT Support for Small and medium sized businesses in Texas
1 年One thing that I really wish Salesforce did after acquiring Steelbrick is to make the tooling around QCP better. The experience as a developer building QCP code is less than ideal and becomes a bigger problem if you try to overextend the number of use cases it can solve for.