Skip to main content
Build the future with Agentforce at TDX in San Francisco or on Salesforce+ on March 5–6. Register now.

Formulate Your Conditions and Actions

Learning Objectives

After completing this unit, you’ll be able to:

  • Construct price rules that use basic formulas in conditions and actions.
  • Check formula syntax using core Salesforce tools.
  • Describe the limitations of formulas in conditions and actions.

Looking Up to Your Relatives

When you constructed the price rule in the last unit, you made the first price condition evaluate the quote’s AccountIndustry__c field. You did so by choosing the right values for the Object and Field fields.

Price condition record with Object and Field values.

Object/Field combinations can only identify fields on the quote, quote line, or product option objects. That’s why Team Trailhead had to create the AccountIndustry__c formula field on the quote object. Using a formula field to bring data into the quote record works fine, but there’s another way that side-steps the custom field requirement.

To illustrate this other method, let’s imagine a new use case. AW Computing would like to give new customers a one-time introductory price on SD Cards, reducing their price by a flat $25. The company already identifies new customers by setting the Type picklist on the opportunity to “New Customer.” That field should determine whether or not the price rule runs.

For this rule, instead of using a custom field to pull Type onto the quote, you reference it directly from the opportunity using what’s called a Tested Formula. Let’s see how to use the Tested Formula, starting with a new price rule.

  1. In the navigation bar, click Price Rules.
  2. Click New.
  3. For Price Rule Name, enter New Customer SD Card List Price.
  4. For Evaluation Scope, choose Calculator.
  5. Check Active.
  6. Click Save.

Now that you have a price rule record, it’s time to make a condition that tests if the opportunity Type field has a value of New Customer.

  1. In the Price Conditions related list, click New.
  2. For Object, choose Quote.
    Choosing Quote tells CPQ which object contains fields available to use in the Tested Formula, which you enter in the next step.
  3. For Tested Formula, enter SBQQ__Opportunity2__r.Type.
    This is a basic cross-object formula like the kind you learn about in the Formulas and Validations badge. Cross-object formulas use lookup fields (such as SBQQ__Opportunity2__c) to reference data on the related object.
  4. For Operator, choose equals.
  5. For Filter Type, choose Value.
  6. For Filter Value, enter New Customer.
  7. Click Save.

This price condition compares two pieces of data just like the conditions from the last unit, the difference is that one piece of data comes from an entirely different (but related) object.

Referencing related data is great, but there is a big limitation to price action formulas: You may only reference data on objects immediately related to the quote, quote line, or quote line group. In other words, SBQQ__Opportunity2__r.Type is fine because there’s a lookup to the opportunity on the quote. But SBQQ__Opportunity2__r.CampaignId.Type is not since there is no lookup to the Campaign object on the quote, quote line, or quote line group.

With that caveat out of the way, let’s create another price condition, this time checking if the product is an SD Card.

  1. In the Price Conditions related list, click New.
  2. For Object, choose Quote Line.
  3. For Field, choose Product Code.
  4. For Operator, choose starts with.
  5. For Filter Type, choose Value.
  6. For Filter Value, enter SDCARD.
  7. Click Save.

Great, now that your price conditions are ready, you can move on to the price action.

A Price Action with a Pocket Calculator

AW Computing wants to adjust the price book price of SD Cards by -$25, and use that value for List Price. That makes SBQQ__ListPrice__c the target of this price action, same as your last rule. But unlike your last rule, you can’t just type 400 into the price action Value field. Instead, you skip the Value field and use the Formula field. Let’s see what that looks like by making a new price action.

  1. In the Price Actions related list, click New.
  2. For Target Object, choose Quote Line.
  3. For Target Field, choose SBQQ__ListPrice__c.
  4. For Formula, enter SBQQ__OriginalPrice__c - 25.
    Formula is yet another CPQ field that uses syntax just like a custom formula field. That means you can use math operators like the minus symbol. In this expression you use the API name of Original Price, which represents the price book price.
  5. Click Save.

Excellent, you’ve finished another price rule! This rule applies to any SD Card quote lines, as long as the quote is made for a new customer. Let’s test it with one such quote.

  1. In the navigation bar, click Quotes, then choose the All list view.
  2. Click Q-00049.
  3. Click Edit Lines.
  4. Click Add Products.
  5. Check ROUTER and SDCARD256GB.
    The SD Card price should be affected, but the router’s shouldn’t. This is a quick way to negative test one of the conditions.
  6. Click Select.
  7. Click the quote line drawer arrow ( Quote Line Drawer expand icon ) for the SDCARD256GB quote line.
    This reveals additional price fields such as Original Price, which is $85. That’s good because List Unit Price is $60. The math checks out! Also, the other quote line for the router should not be affected by the rule.
  8. Click Cancel.

As usual, if this were real life you’d want to test to make sure the rule doesn’t run when the opportunity Type field isn’t “New Customer.” But we won’t make you do that here.

Write Formulas with Care

The formulas used in this scenario were intentionally made to be simple. But in real life they can be very complex, involving functions along with fields and math operators.

If you’ve ever written a formula with even a little complexity, you know just how easy it is to mess up the syntax. It’s the whole reason there’s a Check Syntax button on the custom formula setup page. Unfortunately, there’s no Check Syntax button when you make price conditions and price actions. Even worse, you’re allowed to save conditions and actions that use incorrect syntax for a formula. That’s a real problem because it results in an error message that pops up in the Quote Line Editor, and prevents quote lines from being added.

Alert message with formula error text.

Thankfully there’s a helpful trick for checking syntax, which is to use the Check Syntax button that exists in core Salesforce.

Formula field setup page with Check Syntax button.

It’s a bit roundabout, but you can get there by pretending to make a new formula field.

  1. Click Setup gear icon and click Setup. The Setup page opens in a new tab.
  2. Click Object Manager.
  3. Click Quote Line.
  4. Click Fields & Relationships.
  5. Click New.
  6. Click Formula.
  7. Click Next.
  8. For Field Label, enter Check Syntax.
    It doesn’t actually matter what you name it since you won’t save the field. Just make sure it’s unique.
  9. For Formula Return Type, choose Currency.
  10. Click Next.

At this point you should be on the page where you can write and check your formula as much as you want. When you’re happy with the formula, highlight and copy it. In another tab, create a new price action and paste the copied contents into the Formula field. Once you save the price action, you can close the Setup tab since you don’t want to save the temporary formula field.

When you pretend to make a formula field using the steps above, the object you choose in step 3 makes a difference! You should choose the object that aligns with the Object field of the price condition (or Target Object field if you’re making an action). In the example above you’re directed to choose Quote Line in step 3 so that you can construct a formula using fields available on the quote line object, such as SBQQ__OriginalPrice__c.

The trick of using the core Check Syntax button works most of the time, but not always. Some core Salesforce functions are not supported by CPQ, nor are global variables. For example, using the ADDMONTH() function in a price action results in yet another error message in the Quote Line Editor. So, it’s possible to make a formula with proper syntax, but CPQ can’t handle it anyhow. A list of unsupported functions can be found in the Salesforce CPQ Advanced Calculator supported formulas help article.

Formulas are powerful, but they demand respect. Always thoroughly test your work whenever using formulas for price conditions or price actions.

Resources

Share your Trailhead feedback over on Salesforce Help.

We'd love to hear about your experience with Trailhead - you can now access the new feedback form anytime from the Salesforce Help site.

Learn More Continue to Share Feedback