when I try to run the code below I am getting this error: 'Too many DML rows: 10001'. The object that I am trying to update is one of the main object in the org. so it has multiples triggers, workflows, etc. and one API that runs all day long. I am trying to update 29000 records. can anybody please tell me why i am getting this error or if something is wrong with the code. I will appreciate any help!
Class code:
public class updateNRProdObject{
public Decimal Debug{ get; set; }
public void updateObject(){
List<NRProducts__c> products = [SELECT id FROM NRProducts__c WHERE Active__c = true];
Debug = products.size();
for(NRProducts__c p : products){
p.Active__c=false;
}
update products ;
}
}
Best Answer
You cannot update more than 10000 records in a single transaction.
It looks like you may be doing this in a VF page so you will have to write your VF page to check the status of a batch every so often and then do what you require when it is completed. You can use
<apex:actionPoller>
in your page and run a method to query the AsyncApexJob object to see if the the batch has been completed or not.Please note the examples may need some tweaking as I modified existing code to use your example. I may have missed something....
EXAMPLE PAGE
EXAMPLE CONTROLLER
In order to do what you are wanting to do you will need to write a batch class to perform the updates. The code would look something like:
Then to execute it you would use