You need to sign in to do that
Don't have an account?

Hitting Too many query rows: 50001 only when converting lead to company AND opportunity
Hi, could use some thoughts here. Trying to get a trigger to populate a lookup field when an account record is created or updated. I have a custom object, Sales_Grid_Assignment__c, for storing zipcodes and related data. The intent of the trigger is to match the account's zipcode to a custom object record and populate the lookup field with the custom object record id. Code works great in Sandbox. In production, if the account record creation is by lead conversion, I get following error, but only if the user wants to create an opportunity upon conversion as well as a new company record.
Error: System.LimitException: Too many query rows: 50001 (System Code) Class.AssignSalesGrid.getGrid: line 6, column 1 Trigger.PrimaryAccountTrigger: line 4, column 1
I don't have anywhere near 50,000 custom object records, but I tried putting a LIMIT on the query anyway. No joy. Anyone see any glaring omissions or mistakes? Thanks!
Here is the code for Trigger and Class...
TRIGGER:
trigger PrimaryAccountTrigger on Account (before insert, before update) {
LIST<Account> company = Trigger.new;
AssignSalesGrid.getGrid(company);
}
CLASS:
public class AssignSalesGrid {
public static void getGrid(LIST<Account> company){
List<Sales_Grid_Assignment__c> salesgrids = new List<Sales_Grid_Assignment__c>();
salesgrids = [Select Id, Name
from Sales_Grid_Assignment__c LIMIT 50000];
Map <string,Id> mapGrids = new Map<string,Id>();
for (Sales_Grid_Assignment__c sg: salesgrids) {
mapGrids.put(sg.Name,sg.Id);
}
for (Account a :company){
a.Sales_Grid_Assignment__c = mapGrids.get(a.BillingPostalCode);
}
}
}
Well you were close...
All Answers
Well you were close...
Thanks, Avidev9! I see, I went at it a bit backwards. Let me play with your solution and I'll let you know if that did the trick.
Yep, did the trick. Just had to add the WHERE clause before the IN. Thanks!!