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

System.LimitException: Dlrs : Too many query rows: 50001 #1484

Closed skalra-sf closed 2 months ago

skalra-sf commented 2 months ago

Background: Org has 9 or so custom rollups and every time staff does a bulk/mass update of Orders, Org hits the error "CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY: dlrs_OrderTrigger: System.LimitException: dlrs:Too many query rows: 50001. You can look up ExceptionCode values in the SOAP API Developer Guide." If we disable/remove the Trigger Apex class (DLRS app> Manage Lookup summaries> Manage Child Trigger) then in the debug log we have noticed that the returned row size reduces, but I’m guessing trigger is required for the custom roll ups. Right now the work around is to update rather less number of Orders.

aheber commented 2 months ago

@skalra-sf we recommend questions like this should be asked in the Trailblazer Community Group where many more people are available to provide recommendations. I'll give a quick answer to what is going on and a couple of options.

If your rollups are in real-time then inside of the same transaction we have to load the configs, process the rollups, and write results to the parent record. The error you're getting is often associated with the "process the rollups" phase of that action. If the total sum of all children queried from the database is > 50,000 then you are going to hit that limit. Often times rollups between the same parent and child can't be grouped in the same SOQL query so the same child records are queried multiple times for different rollups. This becomes a math problem for how many records can you update and still stay inside the limits, constraining the size of your bulk update batches. You can try and reduce the batch size in hopes of limiting this. There are minor updates over the last few years in DLRS to reduce these numbers but nothing I would suggest would definitely solve all your problems. You can try making sure you're on the latest version (v2.21 as of now) to try and improve the performance but I suspect it will not outright solve your problem.

The best recommendation right now is to consider deactivating the rollups during the bulk load then reactivate them after, as well as performing a "Full Calculation" to get the parent numbers back in sync. You can also look at using a Scheduled Calculation mode but that still requires the triggers and results in pressure on the 10k DML limit instead of the 50K query limit. Results may vary on if that is a better strategy for you or not.

I'm going to mark this as closed. Should you have additional questions or needs please use the Trailblazer group.

Thanks