SFDO-Community / declarative-lookup-rollup-summaries

Declarative Lookup Rollup Summaries (DLRS) is a community built and maintained Salesforce application that allows you to create cross object roll-ups declaratively - no code! For install instructions and documentation, visit our website https://sfdo-community-sprints.github.io/DLRS-Documentation/
https://sfdo-community-sprints.github.io/DLRS-Documentation/
BSD 3-Clause "New" or "Revised" License
690 stars 235 forks source link

More detailed logs around "System.LimitException: dlrs:Too many query rows: 50001" error #1350

Closed delan-flywheel closed 4 months ago

delan-flywheel commented 1 year ago

The Problem In our org, we are experiencing the System.LimitException: dlrs:Too many query rows: 50001 error. In addition to the default rollups in the NPSP, we have created a number of custom rollups through the DLRS package, so this is to be expected.

We have tried manipulating the batch size up and down in both Custom Settings and NPSP Settings to no noticeable effect—the emails keep coming. No matter what we change, whether it's the Batch Sizes in NPSP settings or the Batch Sizes for the the DLRS package in Custom Settings, the exception keeps coming up.

As part of diagnosing and fixing this error, we wanted to explore the following two questions:

  1. What Objects/Rollups are causing us to run into this limit and therefore what's batch size would be best to avoid it?
  2. As a matter of due diligence, and in order for us to sanity check, are there any rollups that might not be correct as a consequence of this error?

As it stands, it's a bit of a black box, and we're not sure where to proceed.

Solution The ability to access more detailed logs surrounding this error.

Also, any guidance besides what's in the documentation about what we should set the batch size to so we don't get the email anymore would be great. :)

aheber commented 1 year ago

@delan-flywheel, I'll do my best to provide some answers but if you haven't already, I would recommend reaching out to the Trailblazer Community Group for DLRS with additional questions.

When this situation occurs, execution is halted. There is no chance for DLRS to report better logs or improve the error message. Hitting these hard limits in Salesforce stops execution of the code and returns an error. You could look into an Apex Debug log and find the most recent SOQL query that was started and likely find the culprit but if you're not already familiar that could be a big jumping off point.

As for the batch size. It depends on your context. Batch Size in DLRS (I don't know about NPSP) is about the Full Calculate or Scheduled Calculate modes. If this error is occurring as part of a record save the batch settings aren't going to help.

Most commonly we see this when a given parent has lots of children (50K+) or when many rollups are running over a medium sized amount of children, 5 rollups against 10,001 children, can also trigger the same problem. If you have 20 rollups and 2,501 children you could experience the same thing.

This could also be that you're triggering a lot of actions on the parent record or siblings, if you have other automations they can all compound into pulling too many records from the database for processing, which is what causes that error.

You could try and move some of your DLRS rollups to scheduled and make sure you have the Apex class to process those items scheduled in your org, usually at least once a day. That can be a way to relieve pressure on the record save while still having mostly up to date rollup values. It depends on how easily you can tolerate the rollup values being out of date for a time.