I'm trying to load Salesforce with some test data for Salesforce CPQ, but can't get the quotes (SBQQ__Quote__c) nor the quote line items (SBQQ__QuoteLine__c) to "recalculate".

My process is to setup fake products, setup some quotes, add random (using chance) line items with random discounts to those quotes for those products.

Clicking save in the Salesforce CPQ user interface for line items, results in a recalculation, but I don't want to have to do this for many quotes and need to trigger it automatically. Any ideas for how to proceed?

// insert products
await connection.sobject('Product2').insertBulk([{Name: 'Test', IsActive: true}])
const products = await connection.sobject('Product2').find();

// insert quotes
await connection.sobject('SBQQ__Quote__c').insertBulk([{Type: 'Quote'}, ...])
const quotes = await connection.sobject('SBQQ__Quote__c').find({Type: 'Quote'});

// add line items with random discounts to quotes
const lineItems = [];
quotes.forEach(quote => {
  const numLineItems = chance.integer({min: 1, max: 10});
  Array.from({length: numLineItems}).forEach(() => {
    const price = chance.integer({min: 100, max: 1000});
    const product =  chance.pickone(products).Id;
    const quantity = chance.integer({min: 1, max: 5});
    const discount = chance.integer({ min: 0, max: 25 });
      SBQQ__Product__c: product.Id
      SBQQ__ListPrice__c: price
      SBQQ__Quantity__c: quantity,
      SBQQ__Quote__c: quote.Id,
      SBQQ__UnitCost__c: price,
      SBQQ__Discount__c: discount
await connection.sobject('SBQQ__QuoteLine__c').insertBulk(lineItems);

// TODO: How to force the recalculation of the line items and quotes?

I tried individually calling .update on each quote and line item and this doesn't trigger recalculation either.

I also looked into hitting this calculate apex endpoint with connection.apex.requestPatch, but it's unclear what format the input needs to be: https://developer.salesforce.com/docs/atlas.en-us.cpq_dev_api.meta/cpq_dev_api/cpq_quote_api_calculate_final.htm


I checked the AsyncApexJob list and see bunch of QuableCalculatorService failures with this error message:

The system can't process API calls currently. Please try again in a few minutes.

  ApexClass.name, Id, CreatedDate, CreatedById, JobType, 
  ApexClassId, Status, JobItemsProcessed, TotalJobItems, 
  NumberOfErrors, CompletedDate, MethodName, ExtendedStatus, 
  ParentJobId, LastProcessed, LastProcessedOffset 
FROM AsyncApexJob 
WHERE CreatedDate >= ${new Date().toISOString()}

This article mentions SBQQ__Quote__c.SBQQ__Uncalculated__c being true means that calculation previously failed and all of my quotes have this set to true.


It then goes on to say

  • The proper way to remedy error message is to run a calculation that successfully completes an update of the Quote. That can be done in one of the following ways:
    • Clicking Edit Lines and then clicking Quick Save or Save in the Quote Line Editor
    • Editing a Calculating field on the Quote and clicking Save to run an asynchronous calculation that must successfully complete.
    • Editing any field on any Quote Line attached to the Quote and clicking Save to run an asynchronous calculation that must successfully complete.
    • Clicking the Calculate button on the Quote record detail page to run an asynchronous calculation that must successfully complete.

All of the above require manual clicking, which is unfortunate, so still searching for a solution. My only other lead is this article about bulk updating and updating a "calculating field" https://help.salesforce.com/s/articleView?id=000383339&type=1

1 Answer 1


To trigger a recalculation, update all Quote records and modify a field that is in the "Calculating Fields" field set on the Quote object. Optionally, a field can be added to this field set (i.e. a checkbox) to act as a flag for triggering a quote calculation.

Check this article for more info: https://help.salesforce.com/s/articleView?id=sf.cpq_fields_trigger_calc.htm&type=5

Thanks, Hemant

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .