How are Roll-Up Summary fields calculated in the database?

How are roll-up summary fields (RSF) calculated in the Salesforce backend, and what exactly does “Force a mass recalculation of this field” do?

Structure: We have 2 custom objects with a master-detail relationship- Loan__c and its child Transaction__c. We have more than 3 million records on the Transaction table. We have a RSF on Loan__c that simply calculates the Sum of the Transaction__r.Amount__c fields.

What is happening: We have seen more than 100 different Loan__c records show the incorrect value in the RSF. The discrepancy remains for days, weeks, even months even after inserting more child records. Only when we click the “Force a mass recalculation of this field” option is the value is corrected.

Here is the strangest part: The incorrect values are actually off by an exact number in a completely different field on another Loan__c record with a discrepancy. It looks seems an index issue. This is why I think there is more going on in the Salesforce back-end then a simply recalculation.

Tier 3 Support at Salesforce has been trying to resolve this for over 25 days (we have Premier+) but there has still been no resolution.


Don’t hold your breath waiting on Salesforce support 🙂

According to the Salesforce documentation:

Calculating roll-up summary field values can take up to 30 minutes, depending on the number of records affected and other factors.

Based on this, I would expect your rollups to take some time since you have a very large number of records but more than a day definitely sounds like a bug is involved. Salesforce doesn’t appear to publish information regarding how they’ve implemented rollups on the back end but my guess is that they just run a query against the detail object every time there is a CRUD operation and find all records with the same parent as the one that was just modified. They may also be throwing that query into a queue rather than running it synchronously so that would be another potential point of failure.

If each parent record also has a large number of child records (many thousands) and other rollups to calculate then that could explain why you’re running into issues. Are you performing any other rollups using that Transaction__c object? It’s possible that filters on a different rollup are causing some background queries to execute more slowly and causing timeouts during the calculation process, throwing your numbers off until you force a recalculation which then uses the cached results to complete far more quickly.

Salesforce does mention issues with rolling up currency field values to the opportunity level when advanced currency management is enabled so that’s something to check as well (does Loan__c rollup any currency fields to opportunity?):

If you have created a roll-up summary field and it continues to display the spinning hour-glass icon, you may have advanced currency management enabled and be summarizing a currency field on the opportunity object.

Since much of this is speculation about how Salesforce implemented their backend, I’ll at least recommend some next steps for isolating the problem:

  1. Try getting a full sandbox setup (you need it to be a full sandbox so you have an exact copy of production, data and all)
  2. Confirm that you’re able to reproduce this issue there
  3. Try removing other rollups based on Transaction__c fields one at a time and retesting after each one you remove
  4. If the problem is still not resolved, try adding a number field to the Transaction__c object and create a rollup field on the Loan__c object to sum the number field. If this works then it probably has something to do with the currency type which is still a Salesforce bug but at least you could hack around that until they fix it.

Source : Link , Question Author : Yuengling Lager , Answer Author : vscuorzo

Leave a Comment