You need to sign in to do that
Don't have an account?
Anu-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
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
Hi
Thanks for the reply..
Can you modify my code if possible.
Anu
And this code exists in a trigger
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
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.
Batch Apex is the best option you can go for.
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
{
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
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.
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.
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
Did u get any solution for this?
Hi,
Yeah, i have solved this issue through batch apex class..
Thanks,
Lakshmi
Hi,
dont use 2000 limit in batch apex class.. use 200 or 200 below while running batch apex class.
Thanks,
Lakshmi.
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.
Take less batch limit.