You need to sign in to do that
Don't have an account?
kpeterson
This is line 40 within the trigger:
Message Edited by kpeterson on 02-19-2008 06:38 AM
Too Many Query Rows
I'm getting a "Too many query rows" error on a SOQL For Loop. It was my understanding that you could use this approach to prevent governor limits from occurring.
This is line 106 in the test method:
Code:
insert oAssignments;
This is line 40 within the trigger:
Code:
for (OpportunityLineItem oOpportunityLineItem : [SELECT Id, OpportunityId, Project__c, PricebookEntry.Product2Id, PricebookEntry.ProductCode, PricebookEntry.Name FROM OpportunityLineItem WHERE Project__c IN :oProjectsMap.KeySet()])
Code:
System.Exception: Too many query rows: 501 Trigger.AssignmentInsertPopulateProductFlagsHandler: line 40, column 57 System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, AssignmentInsertPopulateProductFlagsHandler: execution of BeforeInsert caused by: System.Exception: Too many query rows: 501 Trigger.AssignmentInsertPopulateProductFlagsHandler: line 40, column 57 Class.TestAssignmentInsertPopulateProductFlags.testAssignmentInsertPopulateProductFlagsHandler: line 106, column 9
Message Edited by kpeterson on 02-19-2008 06:38 AM
I'm running into a similar problem where I have a query in my trigger that could return more than 1000 records (or the Test Method limit of 500). Did you ever find a work around on how to chunk up the query results so you don't get more than the limit? It seems like there should be a way given that it is not inconceivable that there are more than 1000 child records to a parent. My scenario is Leads linked to a custom Campaign object. When I query for all the linked Leads and there are more than 1000, things grind to a halt.
Thanks for any tips you can provide!
I believe I've figured out something: when a query is used repeatedly in a loop, the governor limits apply to the number of rows it returns cumulatively.
In other words, if a query returns 100 rows and is called 10 times, the governor limits think it's returned 100 rows. (Even if the 100 rows returned by each iteration are different.
Here's some code that proves it:
List<OpportunityContactRole> tempOCRs = new List<OpportunityContactRole>([select Id from OpportunityContactRole limit 1]);
Set<Id> realIds = new Set<Id>();
while (tempOCRs.size() > 0) {
System.debug('x');
tempOCRs = new List<OpportunityContactRole>([
select Id, Opportunity.Id, Contact.Id
from OpportunityContactRole
where Contact.Name != 'Attorneys TBD'
and Opportunity.Id not in :realIds
limit :(Limits.getLimitQueryRows()-2)
]);
for (OpportunityContactRole ocr : tempOCRs) {realIds.add(ocr.Opportunity.Id);}
}
I don't yet know what to do about this, but figured I'd share it with the community and see if anyone else has ideas.
I was wrong. Yet again!
It appears that the governor limits on query rows apply cumulatively to all queries in a method.
Annoying, but now I understand what's happenining and will code accordingly.
The key to get this error fixed is ISOLATION of your test data from the org's data. Try executing your test via System.runAs(<User>). I am sure it will help.
This blog post explains this in more detail : http://www.tgerm.com/2010/05/systemrunas-501-apex-query-rows.html