You need to sign in to do that
Don't have an account?
Zamie
System.LimitException: Too many query rows: 1001
Hi,
We are writing a select query in our trigger which is giving such exception but when we are running the query in API, error is not coming and sometimes we can find too less records for this exception.
How to solve this? Any help will be much appreciated.
Here is the code
I suspect that your query is just too broad. a trigger is limited to retrieving 1000 rows in a query, once you reach that mark, the next row retrieved throws an error (hence the 1001). Try adding more constraints to your query... though it appears you have added some already.
If you are able to solve that issue you may run into another issue where you execute too many SOQL statements (the max is 20 in a trigger) because you are executing SOQL queries in a for loop. If you ever insert more than 20 opportunities (using data loader) you will hit the SOQL query govenor limit.
They main problem here is you are querying inside a for loop.
A better practise is to do the loop to build the list of Opportunities you need to query for, query on them AFTER the loop, then process the data.