8

I am getting

Too many Soql rows returned:50001 (limit exception)

on below line of code

list<ContentVersion> cvlist= [Select c.Id, c.ContentDocumentId From ContentVersion c 
                              where c.Syn_Documents__c!=''];

global class DeleteUploadDocOnDeleteOfContentBatchapex implements Database.Batchable<sObject>,Database.Stateful{

global DeleteUploadDocOnDeleteOfContentBatchapex () {

}

global Database.QueryLocator<SObject> start(Database.BatchableContext BC){

   return Database.getQueryLocator('Select u.Id, u.Content_Id__c, u.ContentDocumentId__c From Project_Documents__c u where u.ContentDocumentId__c!=\'\'');

}
 global void execute(Database.BatchableContext BC, List<sObject> scope){

  list<Project_Documents__c> doclist = (list<Project_Documents__c>)scope;

  map<String,Project_Documents__c> umap = new map<String,Project_Documents__c>();

  for(Project_Documents__c u : doclist){
    umap.put(u.Content_Id__c,u);    
 }


 **list<ContentVersion> cvlist= [Select c.Id, c.ContentDocumentId From ContentVersion c where c.Syn_Documents__c!=''];**


 list<Project_Documents__c> docList2 = new list<Project_Documents__c>();

 for(ContentVersion cv: cvlist){
  if(umap.containsKey(cv.Id))
    docList2.add(umap.get(cv.Id));       
 } 


 map<String,Project_Documents__c> umap2 = new map<String,Project_Documents__c>();

 for(Project_Documents__c u:doclist2){
    umap2.put(u.Content_Id__c,u);   
 }


list<Project_Documents__c> docList2Delete = new list<Project_Documents__c>();

for(Project_Documents__c u:doclist){ 
   if(!umap2.containsKey(u.Content_Id__c))
     docList2Delete.add(u);
}


if(docList2Delete.size()>0)
  delete docList2Delete;

}

 global void finish(Database.BatchableContext BC){


   }

}
  • 1
    are you maybe getting too many SoQL Query rows ?? this means you are retrieving too many Rows in your query – ManSpan Oct 7 '13 at 15:30
12

The 50,000 mentioned means you must be encountering a "Too Many Rows Returned" Limit Exception and not a "Too Many SOQL Queries".

Your query is too open ended. Try adding a more restrictive where clause.

[Select c.Id, c.ContentDocumentId 
   From ContentVersion c where c.Syn_Documents__c!='' AND Id in :umap.keySet()];
2

Also, since you are writing Batch Code, you can also try reducing your scope. The standard batch size is 200 records, but you can increase this up to 2,000 or reduce it to, say, 50. If you are querying a lot of records in the Execute method, it might help to reduce the batch size so the total # records queried per batch is < 50,000

You can use the Database.executeBatch(sObject className, Integer scopeSize) method to set the batch size.

Be sure the scopeSize should less than 200.

--from Here.

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.