You need to sign in to do that
Don't have an account?
Toml
Getting 50001 row limit using CUBE and limit 1000
I have the below query in a class that is the controller for a page. The query is executed using Database.query(). There is only 15578 quotes in the database. I have also included below the lines from the error log. Why is thsi happing and how do I go aboutl correcting it. Also I am able to run thsi query with no problem in the developer console.
Thanks
Tom
Query
"select day_only(createdDate) createdonDate, count(createdDate) numCreated, sum(TotalPrice) amount, status, grouping(status) grpStatus FROM Quote WHERE ContactId != null group by cube(day_only(createdDate), status) order by day_only(createdDate) desc limit 1000"
Error log
14:42:47.097 (97511178)|SYSTEM_METHOD_ENTRY|[177]|Database.query(String)
14:42:47.098 (98616275)|SOQL_EXECUTE_BEGIN|[177]|Aggregations:0| select day_only(createdDate) createdonDate, count(createdDate) numCreated, sum(TotalPrice) amount, status, grouping(status) grpStatus FROM Quote WHERE ContactId != null group by cube (day_only(createdDate), status) order by day_only(createdDate) desc limit 1000
14:42:47.275 (275728038)|SOQL_EXECUTE_END|[177]|Rows:1000
14:42:47.275 (275768494)|EXCEPTION_THROWN|[177]|System.LimitException: Too many query rows: 50001
Thanks
Tom
Query
"select day_only(createdDate) createdonDate, count(createdDate) numCreated, sum(TotalPrice) amount, status, grouping(status) grpStatus FROM Quote WHERE ContactId != null group by cube(day_only(createdDate), status) order by day_only(createdDate) desc limit 1000"
Error log
14:42:47.097 (97511178)|SYSTEM_METHOD_ENTRY|[177]|Database.query(String)
14:42:47.098 (98616275)|SOQL_EXECUTE_BEGIN|[177]|Aggregations:0| select day_only(createdDate) createdonDate, count(createdDate) numCreated, sum(TotalPrice) amount, status, grouping(status) grpStatus FROM Quote WHERE ContactId != null group by cube (day_only(createdDate), status) order by day_only(createdDate) desc limit 1000
14:42:47.275 (275728038)|SOQL_EXECUTE_END|[177]|Rows:1000
14:42:47.275 (275768494)|EXCEPTION_THROWN|[177]|System.LimitException: Too many query rows: 50001
If you run this query in the Developer console's "Execute Anonymous" window and view the log, how many rows are you using there? Remember, the governor limits for rows is cumulative across the lifetime of the transaction not just a single query.
All Answers
Because of this, it takes in ALL of your Quotes where ContactId != null (probably more than 5000 rows) and and after it does all of your aggregations (if it hadn't have hit the 5000 limit) it would then limit those results down to 1000 rows. To not hit this limit, you will need to add additional criteria to your WHERE clause
[1] http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_SOQL_agg_fns.htm
Tom
If you run this query in the Developer console's "Execute Anonymous" window and view the log, how many rows are you using there? Remember, the governor limits for rows is cumulative across the lifetime of the transaction not just a single query.
Thanks