22

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.

  • 2
    From Roll-Up Summary Field: You aren’t prevented from creating roll-up summary fields that can result in invalid values, such as February 29 in a non-leap year. If a roll-up summary field results in an invalid value, the value is not recalculated. The field continues to display with an invalid roll-up summary icon (invalid_roll-up_summary) until you change the values being summarized. – Adrian Larson Aug 30 '16 at 14:31
  • 1
    Are there any filters applied to the child records? From my experience with dealing with SF support they tend to spend a lot of time "investigating" the issue, and it seems that it could be reassigned multiple times and new person not always are diving into all the details. Make sure they will record it as a known issue if there will be no fix to this. Also, do escalate the case when there is on response or they are sending a basic "still looking into" response for a long time. – o-lexi Aug 30 '16 at 16:36
  • There are zero filters on the RSF. It is simply a Sum of the Amount (Currency) field on the child Transaction records. – Yuengling Lager Aug 30 '16 at 17:12
  • @YuenglingLager Is multi-currency enabled in the Org? See also: When does the Roll Up fields are calculated? – Daniel Ballinger Sep 2 '16 at 1:13
  • @DanielBallinger No, multi-currency is not enabled nor was it ever enabled. – Yuengling Lager Sep 2 '16 at 15:08
7
+50

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.
  • We do have other roll-up fields on the Loan__c object therefore a timeout and cached is the most plausible explanation. Though this does not account for the transposed values with I suppose can be chalked up to a Salesforce bug. This issue is reproducible in a full copy Sandbox-- the most frustrating part is that salesforce support was able to see this bug occur in the full copy sandbox and still have the RSF show incorrect values even after adding new child records. – Yuengling Lager Sep 6 '16 at 19:47
  • I have question, we have edit Roll-up summary field and choose the calculation options to Force a mass recalculation of this field so hopefully it will recalculate the record.However once I click Save, I check Calculation Option is set back to Automatic Calculation . I keep try to set it to Force a mass recalculation but it keep reversing. Is this normal behaviour ? – unidha Sep 25 at 2:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.