Happy Business Starts Here

Re: Design Your Personal Configurable Quoting Bot, with Zuora’s Rules Engine

Zuora Staff

Hello! I’m Eric Neto, Engineering Manager on the Zuora for Salesforce Team.  We manage a set of products built on the Force.com platform to integrate the awesome CRM functionality of Salesforce with the awesome Subscription Management capabilities of Zuora. Our goal is to provide the best possible front office experience that enables users to get the most out of their Zuora integration.

The Best Front Office Experience

The thing is, “best possible front office experience” means a lot of different things to a lot of different customers.  A hosting company that sells committed volumes of data and storage to small businesses will likely require a vastly different experience than a freight technology company that sells services and hardware to fleets of trucks.  Even within a company, different business units or users often have different front office flows. This requires a strong emphasis on the ability to quickly customize the product to suit whatever your needs may be.

If you’re a developer, the Salesforce platform is your playground. With our Zuora Quotes package, we expose dozens of plugins and components that you can use to override any part of the quoting flow, including defaulting values, filtering selections, adding pages, as well as modifying pages.  For many companies, however, requests for streamlining sales processes arrive faster than IT departments can keep up with them. For example:

My support fee should always be 20% of the annual platform fee!
   “You can’t have more than one domain plan at a time!
      “For long time customers, upgrade their service and provide them a discount!
         “Customers with more than three products need Premier Support or higher!
            “Any discounts over 20% require supervisor approval!
               “Users who purchased hardware require two years of maintenance!

If you need to maintain code every time a new product is added, or every time a business process changes, it takes time away from more important things.  At Zuora, we set out to provide the same level of control in the hands of administrators, using easily configurable rules built for Subscription Business use cases.

To design this solution, we took all of the most common rules that were requiring custom development to achieve, and identified the components that make up the decisions.  Essentially, all of these rules can be broken into the format of “If this, then do that.” For example, the same requirements from before can be written:

 

“If there is a platform fee, then add support and set its price to 20% of platform
   “If there are multiple domain plans, then show a validation message and prevent submission
      “If the customer’s term exceeds X years, then replace their plan and discount it
         “If a customer has over three products and no support, then add Premier Support
            “If a product’s discount is more than 20%, then flag it for approval
               “If there is hardware, then add two years of maintenance

In other words, all of these use cases are comprised of Conditions and Actions.

Conditions

All of our conditions are evaluated by comparing pairs of values.  In some cases, these include simple static values. In others, we are looking at database fields on the acting object, or objects related to it.

 

Condition


In many cases, we need to roll up how many products of a certain type a customer has.  This necessitates the use of a configurable filtering concept. For example, if my comparison requires the total quantity of all of my software and hardware products that belong to a particular quote, then I can configure my comparison to check the sum the values of all quantity fields that match a filter.

Screen Shot 2017-04-04 at 1.27.59 PM.png


Another need is to use arithmetic calculations between these values to derive either thresholds or new values for comparisons and updates.  For this we introduced a calculated value mechanism that allows formulaic combinations using the value types above.

 

Formula


Actions

Since our Rules Engine is designed to support more than just product selection, an interface was created that could be implemented by any developer using the package, in order to specify the behavior of their actions.  The logic of these actions is specialized for each use case. In the case of product selection, we included implementations that cover most of our bases:
 
1. Adding Products
2. Removing Products
3. Updating Products
4. Validation Disclaimers
 
Bringing It Together

 

Now, administrators can easily configure their rules in a single flow.

 

screencapture-c-na30-visual-force-apex-RuleConfig-1491338392865.png

 
At runtime, the rules engine can be run against any SObject or Apex wrapper, with any set of configured rules.  By parsing the rule metadata, we can determine all of the fields, objects and relationships that need to be retrieved from the database, and use it to build out SOQL queries for missing information.  We then systematically traverse each of the conditional trees, until the condition proves either true or false. On a true condition, we fire off the corresponding actions!
 
The Rules Engine reduces the effort and maintenance costs of custom business rules from days to minutes, and works great with Subscription scenarios.  Another cool way that Zuora assists Quote-to-Cash processes of the Subscription Economy!

1 Comment
Guru

@eric-neto awesome post. We Heart the Rules Engine.