Quote Calculation & Triggering Calculations

by Community Manager ‎09-12-2016 11:56 AM - edited ‎01-04-2018 12:05 PM


This article lists:

  • The events that will cause a Quote to calculate 
  • The order of events that occur upon calculation in Advanced and Legacy Calculators
  • The order of events that occur on a new or existing Record upon a Calculation event
  • How to set fields that will trigger a calculation upon field value modification


Calculation Triggers:

By default, the Quote will be calculated when any of the following occurs:

  • User clicks Calculate in the Line Editor
  • User adds Products in the Line Editor
  • User deletes lines in the Line Editor
  • User clicks Save or Quick Save  in the Line Editor
  • User edits the Quote Header and changes one of the fields that trigger recalculation
  • User edits Quote Line using the Edit button

Calculation Event Sequence (Advanced Calculator - Spring 16 and later versions)

  1. Product and option records are lazy-loaded.
  2. Additional lookup relationships are loaded.
  3. Formula field metadata is retrieved.
  4. Price Rules On Initialization event is executed.
  5. Plugin is initialized if it exists.
  6. Plugin's onInit() method is executed.
  7. Related records are updated, in case the plugin or price rules injected new Ids.
  8. Formula fields are calculated on the Quote Lines.
  9. Formula fields are calculated on the Quote
  10. Formula fields are evaluated on the Quote Line Group
  11. Price Rules Before Calculate event is executed
  12. Plugin's beforeCalculate() method is executed
  13. Update related records again, for the same reasons as in step 7
  14. Quantities are calculated
  15. Plugin's beforePriceRules() method is executed
  16. Price rules On Calculate event are evaluated
  17. Plugin's afterPriceRules() method is executed
  18. Update related records yet again
  19. After Price rules have run, ensure that any dynamically injected discount schedules are loaded properly.
  20. Quantities are indexed according to schedule, and group keys.
  21. Target Calculator resets discounts if a target amount exists.
  22. Quote and Group totals are reset.
  23. Calculate fixed items.
  24. Calculate dynamic items.
  25. Calculate totals.
  26. If target amount is specified, Target Calculator applies discounts such that it is reached.
  27. Components are rolled up.
  28. Price Rule After Calculate event is executed.
  29. Plugin's onAfterCalculate() method is executed.
  30. Update related records again.
  31. Quote Line formula fields are re-evaluated.
  32. Quote Line Group formula fields are evaluated
  33. Quote formula fields are evaluated.
  34. Group- and Quote-level totals are reset and recalculated, since the line-level totals may have changed.
  35. Quote Summarizer is invoked to summarize MDQ Segments and Summarized Fields.
  36. Delete the plugin module, if one exists.
  37. Update the related records one last time.

Calculation Event Sequence (Legacy Calculator)

The following sequence of events occurs during each Calculate cycle:

  1. QuoteCalculatorPlugin is initialized (if configured) and onInit() method is called.
  2. Transaction savepoint is set.
  3. Quote record is upserted.
  4. Quote Line records are reloaded (upserted and queried) to evaluate formula fields used in price rules.
  5. QuoteCalculatorPlugin.onBeforeCalculate() method is called with original (unflushed) quote lines.
  6. Quantities are calculated (component quantities, batch quantities, etc.)
  7. QuoteCalculatorPlugin.onBeforePriceRules() method is called with original (unflushed) quote lines.
  8. Price rules are evaluated against reloaded (flushed) quote lines.
  9. QuoteCalculatorPlugin.onAfterPriceRules() method is called with original (unflushed) quote lines.
  10. Native calculation logic is executed.
  11. QuoteCalculatorPlugin.onAfterCalculate() method is called with original (unflushed) quote lines.
  12. Quote, Quote Line, and Quote Line Group records are reloaded again to evaluate formula fields changed as a result of above processing.
  13. Transaction is rolled back.

Calculate Event Order of Operations for Formula Fields, Workflow Rules & Price Rules

Salesforce CPQ will process events in the following order upon a Calculate Event:

  1. Formula fields will evaluate.
  2. Workflow Rules will evaluate. (Workflow Rules will be evaluated a second time if required by Field Updates and if Conditions Met are still True.)
    • If Workflow Rules modify any underlying fields, formula fields will re-evaluate.
  3. Price Rules will evaluate based on the following logic:
    1. Salesforce CPQ applies internal logic - this is what the price engine does inside the package, such as calculating quantities, calculating all price levels from list to regular to customer, etc.
    2. Salesforce CPQ sets the Price Rule's Incomplete field to False.
    3. Salesforce CPQ writes the Record. If the Record is written a second time (via the calculate events of clicking Save, clicking Calculate, or adding a Product to the Quote), Workflow Rules and formulas will re-evaluate.

Note: Salesforce CPQ prevents users from chaining multiple calculations within one transaction. This allows Salesforce CPQ to stay within Salesforce platform governance limits. Salesforce CPQ sets a flag the first time CPQ triggers run for calculations that prevent the trigger from firing again. As a result, workflow rule and process builder updates to a calculating field do not trigger a second calculation.




Salesforce CPQ allows users to specify fields that will trigger a recalculation of Quote Line Item values when that field's value is changed.



This feature would be useful for users who want a quote to change prices proportionally to a change in Subscription Term. For example, changing the Subscription Term from 12 to 24 months would cause the Quote price to double.



  1. Navigate to the page layout of your desired Quote.
  2. Navigate to the Field Sets related list and click Edit next to the Calculating Fields line.sequence.png
  3. Drag and drop your desired fields from the field list into In the Field Set.

Note: To detect upserts of any Quote Lines that will later be rolled back, you can examine the SBQQ__Incomplete__c field. This field is set to TRUE during a rolled-back transaction.

Note: A Price Rule cannot depend on a Workflow Rule that is itself directly or indirectly dependent on another Price Rule. All formulas or Workflow Rules must be fully evaluated before you enter the Price Rule stage of the Calculate sequence.

by KenWarchalowsky
on ‎11-29-2017 09:55 AM

Where in this process does the sync to the Opportunity Product occur? 

Currently we are running into an issue where a quote line formula field is dependent on a Quote field updated via workflow. Prior to the workflow running the sync is occurring: The Opportunity Product is left with null values and the Quote Line is reflecting the correct values.

Our fix was to run a Price Rule to update the Quote Line field rather than using formulas. Any recommendations for similar scenarios?