4

I am getting this error while running batch class. I am using sub query in query locator.

String SOQL_Query = 'Select id,name,(select id,name from Safety__r) from Study__c where Reference_Date <= TODAY limit 1000';

And in execute method,iterating over returned Study records and putting child records in Map.

for(Study__c study:recs){

     safMap.put(study.id,study.Safety__r); 
   }

for(Study_CELG_IPS__c study:recs){

     flag=false;
     if(safMap.get(study.id).size()==0){
        flag= true;    
    }else{
         safList= safMap.get(study.id);
     }

   //code
}
3

This problem is related to your query because it contains more then 250 rows.

So you need to separate it into another query. That will solve your problem

As per Salesforce docs

This error happens when you're trying to use an aggregate function (like COUNT) on a query that has too many rows. To fix the error remove this condition:

for (childtype ch : Parent.children) {

//do some logic...

}

Alternatively, have a map of parent to child objects and get the size of each key from the map.

Reference

Reference 2

  • Hey Tushar,I have used Map of parent to child objects,Study being Parent and Safety being child and added all related child records to Map.Then,I am checking if there are Study (Parent) records which are having no Safety(child) records. I have added that portion of code . – newbiesalesforce Sep 8 '16 at 7:09
  • @newbiesalesforce You need to make two query and then map of all child with their parent and using that map find the children list. – Tushar Sharma Sep 8 '16 at 7:43
  • 2
    @TusharSharma Thanks for this answer! the imortant part is that 250 rows is the limit, thank you! – Basti Sep 16 '16 at 8:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.