+ Start a Discussion
Madhavi ValavalaMadhavi Valavala 

Batch: Too many query rows: 50001

I am executing the batch manually from the developer console and I am getting this error. 

System.LimitException: Too many query rows: 50001

Details Below: 

Batch Execution:
batchDataGeneration batchable = new batchDataGeneration();

Error Information: 
14:09:41:000 FATAL_ERROR Class.Database.QueryLocatorIterator.hasNext: line 41, column 1
14:09:41:000 FATAL_ERROR Class.batchDataGeneration.execute: line 516, column 1

This is the code from Line 41 and Line 516.

Line 41 Code:

return Database.getQueryLocator([SELECT id,
            Activated_Date__c, //Line 41
            FROM Measure__c
            status__c =:System.Label.Activated

Line 516 code:

Database.QueryLocator qplant = Database.getQueryLocator([Select Id, Fiscal_Period__c, Plant__c,Date__c, Measure__c from Plant_Measure__c where Measure__c in : measureToExecute]);
            Database.QueryLocatorIterator plantIterator =  qplant.iterator();
            while (plantIterator.hasNext()) //Line 516
                    Plant_Measure__c a = (Plant_Measure__c)plantIterator.next();

I know the counts are based on the transaction and not on a single query output. I have used Database.querylocator and still I am getting this error. Could someone help me what could be the problem with this code?
sai kumar 433sai kumar 433
No of query limits exists  through query 50000 records only
Hi Madhavi,

Salesforce has its governor limit that in a single thread, you can only query 50000 rows / records. Please add "Limit" condition while quering records.

Hope this will help you. 
Let me know if you still need assitance on this. 

email: gauravgarg.nmims@gmail.com
skype: gaurav62990
Chaitanya Korada 4Chaitanya Korada 4
Hi Madhavi

I am facing the sam issue, did find any solution or alternative to this,

Thanks in advance.