You need to sign in to do that
Don't have an account?
Yogesh Malbhage 18
"Too many soql rows 50001" exception apex class
We are fetching records from contact provided sufficient conditions and it is hitting the governor limit of rows returned. It required to fetch all these rows. Could you help me to handle this exception ASAP?
Sorry for this issue you are facing.
There is a limit to the number of records that can be retrieved by the SOQL Query which is 50000 records. Attempting to query the records having the number more than this will give the error which you are getting.To query the records more than its limit, you need to use a Batch Class which provides a fresh limit of 50k records by resetting the limits.
The exception is being thrown because the maximum number of rows you can return in SOQL calls in Apex is 50000.
This happens If you don't have a where clause In addition, they do not have a LIMIT clause which could prevent this exception.
In your VF Page, you could try to limit this to only Products in a specific Pricebook, or only products of a certain type, etc.
It looks like your org has an extensive catalog, so think about the use case. Even if you could display 50,000 records on a page, who is going to be able to read that?
If you add Where and Limit clauses to your SOQL, you'll be able to resolve the error.
- https://www.forcetalks.com/salesforce-topic/what-is-system-limitexception-too-many-query-rows-50001-in-apex-and-triggers/
Hope this helps.Kindly mark this as solved if the reply was helpful.
Thanks,
Nagendra
The query is already in Batch class and we are fetching these records for some calculations (So we need all of them).