Approve Records in Bulk Using Apex

The following sample code approves records in mass using apex. Below example just uses Account object’s record. Please feel free to update it as per your need.

Set<Id> accIds = (new Map<Id, CCProduct__c>([SELECT Id FROM Account WHERE LASTModifieddate=today])).keySet(); // Query your target set of records
Set<Id> pIds = (new Map<Id, ProcessInstance>([SELECT Id,Status,TargetObjectId FROM ProcessInstance where Status='Pending' and TargetObjectId in :accIds])).keySet();
Set<Id> pInstanceWorkitems = (new Map<Id, ProcessInstanceWorkitem>([SELECT Id,ProcessInstanceId FROM ProcessInstanceWorkitem WHERE ProcessInstanceId in :pIds])).keySet();

List<Approval.ProcessWorkitemRequest> allReq = new List<Approval.ProcessWorkitemRequest>(); 
for (Id pInstanceWorkitemsId:pInstanceWorkitems){
        Approval.ProcessWorkitemRequest req2 = new Approval.ProcessWorkitemRequest();
        req2.setAction('Reject'); //to approve use 'Approve'
        req2.setNextApproverIds(new Id[] {UserInfo.getUserId()});

        // Use the ID from the newly created item to specify the item to be worked

        // Add the request for approval
Approval.ProcessResult[] result2 =  Approval.process(allReq);