• Madhavi Valavala
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies
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();
database.executeBatch(batchable);

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,
            Name,
            Frequency__c,
            Start_Date__c,
            Activated_Date__c, //Line 41
            Date_to_Create_Next_Year_s_Targets__c
            FROM Measure__c
            where
            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();
                    mapPlantMeasureIds.put(a.id,a);
            }

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?