function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
nagalakshminagalakshmi 

Too many query rows 50001

H,

 

When i am trying to delete some records from object,  i am getting this error  'Too many query rows 50001'. I have used the limit as 50000 in query. Still i am facing the same problem. How can i solve this issue.

 

I have used the limit in my query like as

 

for(store__C ss:[select id,Retail_Brand__c from store__C where Retail_Brand__c =:rid limit 50000])
setsid.add(ss.id);
For(StoreProduct_category__C spc:[select id,store__c,Product_category__C from StoreProduct_category__C where Store__c in : setsid limit 50000])
{
delspclist.add(spc);
system.debug(delspclist.size()+'del===');
}
if(delspclist.size()>0){
deletestoreproducts del=new deletestoreproducts(delspclist);
database.executebatch(del,1000);

 

I am getting the error at  the line, which is bold in my code.

 

Thanks

AmitSahuAmitSahu

As the first execution, where you are constructing the set may not contain more than 50000 record ids'.

 

What happens if you are removing the limit from the second for loop ? 

Anup JadhavAnup Jadhav
Integer counter = 0;
for(List<store__C> storeList:[select id,Retail_Brand__c from store__C where Retail_Brand__c =:rid]) {
  counter = counter + 200;
  for(Store__c ss: storeList) {
    setsid.add(ss.id);
  }
  if(counter > 50000) {
    break; 
  }
}
For(StoreProduct_category__C spc:[select id,store__c,Product_category__C from StoreProduct_category__C where Store__c in : setsid limit 50000])
{
delspclist.add(spc);
system.debug(delspclist.size()+'del===');
}

 Try the code block above, and see if it works.

 

Regards,

A

nagalakshminagalakshmi

Hi Jo,

 

Set having only 174 ids. In both conditions i am facing the same issue. if for loop having 50000 limit or not. Please help me out.

 

Thanks

nick1505nick1505

Hi,

 

The 50,000 records limit is for the overall instance. So if you are having 2 queries executed in one instance the sum of records returned by both the queries should not exceed 50,000.

Can you check if the records returned by both the queries is not more than 50,000.

Also try limiting the records to 10,000 and 40,000 in both the queries accordingly and check if the error still exists.

 

Let me know incase of any issue!