+ Start a Discussion
Anu-SFDCAnu-SFDC 

Too many dml rows:10001

Hi

 

I have the following query in my code

 

list<npo02__Household__c> DeleteHouseholds=[select Id from npo02__Household__c where Id NOT IN :TranHouseHoldIdSet];

 

 

     if(!DeleteHouseholds.isEmpty()&& xmlvalue[0].Households__c == true){
      delete DeleteHouseholds;
      }

 

 

But one of my client has 12000 dummy households which satisfies the above query.. But there is a limit of 10000 dml rows. So he is getting too many dml rows :10001 exception..

 

I know I can put a limit, but I want to delete all at a time..

 

Can any of you advice me please

 

Thanks

Anu

pbattissonpbattisson

Anu

 

Look into Batch Apex and you will be able to do this in batches of records allowing you delete a far greater number. This will also make your code more extensible for the future when you wish to do similar again on such a large number of records.

 

You can find out more about batch apex here:

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_batch_interface.htm

 

I hope thathelps

 

Paul

Anu-SFDCAnu-SFDC

Hi

 

Thanks for the reply..

 

Can you modify my code if possible.

 

Anu

Anu-SFDCAnu-SFDC

And this code exists in a trigger

 

pbattissonpbattisson

Anu

 

You should be careful putting things in triggers that update a large number of items (or in this case deletes them) as you can then fire off more triggers from this causing you more issues. I would recommend you look in to seeing whether you could remove some of the dummy data that is not needed or refactor you code to include an implementation of a class utilising batch apex to do this. 

 

As for writing it in a trigger you cannot do this as it needs to be in a separate class implementing the Database.Batchable interface (as is described in the link I mentioned above).

 

 

Paul

Shashikant SharmaShashikant Sharma

Hi Anu,

 

There is no way to solve your issue in the trigger till salesforce increases limits. Only possible way is to go with asynchronous call using batch apex or future call or any other asyn. way.

Ankit AroraAnkit Arora

Batch Apex is the best option you can go for.

 

 

Thanks
Ankit Arora

 

nagalakshminagalakshmi

Hi Ankit,

 

I have tried with batch apex class for inserting the records. But i am fcing the similar problem with batch apex also. Can you help me please how to solve this..

 

My code is

global class batchinsert implements Database.Batchable<sObject>
{
Manageproductcategories m=new Manageproductcategories();
global final String Query;
global batchinsert()
{

}

global Database.QueryLocator start(Database.BatchableContext BC)
{
return null;
}

global void execute(Database.BatchableContext BC, List<storeproduct_category__C> scope)
{
/*
List <storeproduct_category__c> lstAccount = new list<storeproduct_category__C>();
for(sobject s : scope)
{
//lstAccount(s);
}*/

insert scope;

}
global void finish(Database.BatchableContext BC)
{
}

}

 

And i am pass the list values from apex class as follows

 

Database.BatchableContext BC;
batchinsert b=new batchinsert();
b.execute(BC,updatestorebrand);

 

updatestorebrand is list name having values. Please help me out.

 

Thanks

 

 

Starz26Starz26

Batch apex works off of a querylocator so you cannot pass in a list of records.

 

in your start method, you need to return the querylocator: i.e.

 

 

String query = 'Select ID From Opportunity';

    return Database.getQueryLocator(query); 

then in the execute method you do stuff with the results.

 

So set up your query to search for the records you want to perform the action on.

 

nagalakshminagalakshmi

Hi Ankit,

 

I am getting Too Many dml rows 10001. I have wrote the @future method for this. But still getiing same problem. Please help me.

 

 

My code is 

 

global class MyFutureClass {
@future
public static void myMethod(set<id> stid, set<string> st )
{
Map<String,Id> stbr1=new Map<string,Id>();
list<storeproduct_category__C> stplist=new list<storeproduct_category__c>();
list<storeproduct_category__C> stplist1=new list<storeproduct_category__c>();
list<storeproduct_category__C> stplist2=new list<storeproduct_category__c>();
for(Product_category__C b : [Select Id,Name from Product_category__C limit 50000])
{
stbr1.put(b.name,b.Id);
}
for(id i:stid)
{
for(String s1:st)
{
storeproduct_category__C s=new storeproduct_Category__C();
StoreProduct_category__C stb=new StoreProduct_category__C ();
stb.Product_category__C =stbr1.get(s1);
stb.store__c=i;
stplist.add(stb);
}

}
system.debug('========' +stplist.size());

for(integer i=0;i<10000;i++)
{
stplist1.add(stplist.get(i));
}
if(stplist1.size()>0)
insert stplist1;

if(stplist.size()>10000)
{
for(integer i=10000;i<stplist.size();i++)
{
system.debug('i========' +i+stplist.get(i));
stplist2.add(stplist.get(i));
}
}

if(stplist2.size()>0)
insert stplist2;

}

}

 

I have called this @future in my normal apex class as  

MyFutureClass.myMethod(setsid,rightvalues1); 

 

setsid is set of ids and right values1 is set of strings. Please help me out.

 

Thanks,

lakshmi

 

SFDC_LearnerSFDC_Learner

Did u get any solution for this?

nagalakshminagalakshmi

Hi,

 

Yeah, i have solved this issue through batch apex class..

 

Thanks,

Lakshmi

SFDC_LearnerSFDC_Learner
But i faced this exception with in trigger code. If we go with batch class then from the trigger it allows only 5 batches [each batch max scope is :2000]. So again with this, we can handle only 10000 rows. Any other solution through trigger to work on this..
nagalakshminagalakshmi

Hi,

 

dont use 2000 limit in batch apex class.. use 200 or  200 below while running batch apex class.

 

Thanks,

Lakshmi.

vivekanandanvivekanandan

I have used batch apex, By using batch apex while scheduling the apex, I am getting this error.

First error: Too many DML rows :10001.

 

We are inserting, updating and deleteing the records based on some conditions in the query. Please advice. This is very urgent.

SFDC_LearnerSFDC_Learner

Take less batch limit.