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

Add "Row Limit" to First Operator rollups to prevent #1251

Closed mpietruszka closed 4 months ago

mpietruszka commented 1 year ago

I noticed you can't add a Row Limit to a First operator rollup - you get the error message that "Row Limit: Row Limit is only supported on Last and Concatentate operators." (side note: there's a typo in that error message, an extra t in Concatenate)

We have a rollup that uses a First operator on CreatedDate, and I want to add a row limit because obviously if I need the first record, I don't need to pull in all of the other child records after that, a First with limit 1 would be sufficient, even.

I'm looking in particular to do this because of records with over 50k rows (yes, I know this isn't recommended, no this isn't something we can change right now) where they will fail without a row limit. (error message: First error: dlrs:Too many query rows: 50001)

I originally wondered if perhaps I can't add that because that's how First operator rollups in DLRS already work/that's built in for those- but I tested on a record with over 50k rows and the rollup failed because of the "Too many query rows" error.

I'm not sure how I'm supposed to effectively get around this too many query rows error in this use case without the ability to add a row limit to the rollup. I'd like this functionality so I can be unblocked here.

mpietruszka commented 1 year ago

Actually - do Row Limits even prevent the "too many query rows" error? I just tried this again with a rollup where I was able to use a Last operator, using a row limit of 1, and I still got the "too many query rows" error when I tried to run a full calculate on a single record that I know has over 50k children. That doesn't make sense to me; with a row limit of 1, this shouldn't be pulling all 50k children.

stephenbrown1 commented 1 year ago

I think we probably need to add some use of the Limits.getLimitQueryRows() and Limits.getQueryRows() to catch this. Re the use of LIMIT still generating the too many rows - suspect yes it's due to first opening the query cursor, then applying the limit, hence if there's >50k records it'll still give an error. Definitely a valid enhancement...

aheber commented 1 year ago

DLRS doesn't apply the row limit at the query level. SOQL doesn't allow "only retrieve x records per parent" so there isn't a way to reduce the number of records read from the database easily using that technique.

You would need to use an action that can perform an aggregation on the value; such as MAX, COUNT, etc... as those will usually reduce the number of records delivered by the SOQL query.

Resolving this can be difficult depending on what value you're trying to display, if you provide more details on your configuration then maybe we can work through how to best set it up for your situation.