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){

 **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){

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

 for(Project_Documents__c u:doclist2){

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

for(Project_Documents__c u:doclist){ 

  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

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()];
| improve this answer | |

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.

| improve this answer | |

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.