+ Start a Discussion
SFDC 2017SFDC 2017 

Too many DML rows 10001 error in Batch class

Hi I am running a batch job in that i am getting Too many DML rows: 10001 error .Eventhough i am spliting the batch every 10000 Records but still i am getting that error.i tried all possible ways still i am getting same error.

List<Candidate__c> Candidatelist = new List<Candidate__c>();
List<Database.Saveresult> saveList = new List<Database.Saveresult>();
 if(Candidatelist!=null && Candidatelist.size()>0){
            integer i=0;
            List<Candidate__c> Candidatelistk = new List<Candidate__c>();
            for(Candidate__c ctc: Candidatelist){
                    saveList.addAll(Database.insert(Candidatelistk, false));//error in this line
            saveList.addAll(Database.insert(CandidatelistK, false));

Thanks in advance
karthikeyan perumalkarthikeyan perumal

for this you should keep in mind that list you are inserting should not  have items more than 10000. so while using batch process please keep your small batch size so in each batch more than 10000 record can not come in list to be inersted at a time. 
because this is salesforce limiation ( not to execute dml on more than 10000 item at once). so we should customize way of creating list. as one way I suggested above.

Hope this will helps you,