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
tbfan6789tbfan6789 

Question on executeBatch - Running into Error Too many DML rows: 10001

I'm working on a schedule class that will update the Cases in Salesforce (Making sure our support are handling the cases within an alloted time). I'm running into the DML rows error. I know that I need to use executeBatch that will handle this problem, but I'm hoping someone can show me how to implement that into this code. Please let me know if there are any problems or questions.

 

global class CaseMonitoring implements Schedulable 
{
	global void execute(SchedulableContext sc)
	{
		
		HandleSLA.Initialize();
		
		RecordType standard_case = [Select ID from RecordType where name = 'Standard CS Case'];
		
		List<Case> CaseList  = [Select id, AccountID, CaseNumber, CreatedDate, Status, Priority, OwnerId,
					Field_Customer_Timer__c, Tech_Timer__c, Escalation_Timer__c, Prev_Flag_ID__c, Flag_ID__c, Escalate_to_Management__c, 
					Escalation_Owner__c, Escalation_Status__c from Case where Status != 'Closed' and RecordTypeId =: standard_case.id ];
		
		if(!CaseList.isEmpty())
		{	
			for(Case cs: CaseList)
			{
				HandleSLA.HandleSLAGroup(cs);
			}
			update CaseList;	
		}
		
		List<Case> CaseCloseList = [Select id, AccountID, CaseNumber, CreatedDate, Status, Priority, OwnerId,
						Field_Customer_Timer__c, Tech_Timer__c, Escalation_Timer__c, Prev_Flag_ID__c, Flag_ID__c, Escalate_to_Management__c, 
						Escalation_Owner__c, Escalation_Status__c from Case where Status = 'Closed' and RecordTypeId =: standard_case.id ];
		
		if(!CaseCloseList.isEmpty())
		{	
			for(Case ccs: CaseCloseList)
			{
				HandleSLA.setSLADate(ccs, '', null);
			}		
			update CaseCloseList;
		}
	}
}