You need to sign in to do that
Don't have an account?
Nihar Sharma
Getting error of "System.LimitException: Too many query rows: 50001" in apex trigger
Hello,
i am suddenly getting the following error in apex trigger :
"System.LimitException: Too many query rows: 50001"
Here is my apex trigger code :
I am using this trigger to set up the records which all are coming from other system using synchronization
i think Batch is very useful to this case but i am not sure how to do it, can somebody help me out
Thanks
i am suddenly getting the following error in apex trigger :
"System.LimitException: Too many query rows: 50001"
Here is my apex trigger code :
trigger SetAmountfromOTTtoSFDC on Opportunity (Before Insert, Before Update) { Map <string, Id> AccountTextIdMap = new Map<String,Id>(); Map <string, Id> ContactTextIdMap = new Map<String,Id>(); if(Trigger.IsInsert || Trigger.IsUpdate){ List<Account> AccList = [select Id, Name, AccountId__c from Account]; for(Account ac : AccList){ AccountTextIdMap.put(ac.AccountID__c, ac.id); } List<Contact> ConList = [select Id, Contact_ID__c from Contact]; for(Contact con : ConList){ ContactTextIdMap.put(con.Contact_ID__c, con.id); } for(Opportunity op : Trigger.New){ if(op.AdrAccountSearchKey__c != Null && op.AccountId == Null){ op.AccountId = AccountTextIdMap.get(op.AdrAccountSearchKey__c); } if(op.AdrContactSearchKey__c != Null && op.Contact__c == Null){ op.Contact__c = ContactTextIdMap.get(op.AdrContactSearchKey__c); } } }
I am using this trigger to set up the records which all are coming from other system using synchronization
i think Batch is very useful to this case but i am not sure how to do it, can somebody help me out
Thanks
Let us know if this will help you
All Answers
How many accounts and contacts? if more than 50,000, you need a queryLocator and a batch (asynchronous for larger CPU time limit).
Governor limits: Total number of records retrieved by SOQL queries 50,000
Two exceptions: queryLocator with scope (50,000,000 records read by max. scope of 2000) and VF page with readOnly="true" (1,000,000 records). Here the only option is the querylocator.
Alain
we have large number of records, let say 2,00,000
Thanks
Let us know if this will help you
Thanks for your valuable time to this question but i used the same logic and worked for me..
i guess you've answered with same logic :)
thanks again !!
Can you please guide me for Batch Apex ? How can i achieve this same logic using Batch Apex ?
Thanks
-Nihar
A batch is totally useless with the Amit Chaudhary's solution.
The code below cannot work because it lacks filters for the queries.
Alain
Thanks Alain :)