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
Santosh Reddy 10044Santosh Reddy 10044 

Trying to recall all the records which were submitted between 3 months But my logic is only working for 1 record ., im trying to bulkify, which is throwing me an error

list<ProcessInstanceWorkitem> workItems = [SELECT Id,ProcessInstance.TargetObjectId,actorid,createddate,CreatedById
FROM ProcessInstanceWorkitem WHERE actorId = '00537000000GePo' and  
                                       ProcessInstance.Status = 'Pending' and 
                                       (createddate> 2018-01-01T01:00:00Z and createddate< 2018-04-30T01:00:00Z) ]; 

system.debug('what is this'+workItems.size());

list<Approval.ProcessWorkitemRequest> y = new list<Approval.ProcessWorkitemRequest>();
Set<Id>tId = new Set<Id>();

for(ProcessInstanceWorkitem ccc : workItems){
    tId.add(ccc.id);
    
}

list<Id> sdcc = new list<Id>();

for(Id ff : tId){
    
    sdcc.add(ff);
}
for(integer i = 0; i< sdcc.size(); i++){
    Approval.ProcessWorkitemRequest pwr = new Approval.ProcessWorkitemRequest();  

pwr.setAction('Removed');
 pwr.setWorkItemId(sdcc[i]);
    pwr.setNextApproverIds(new Id[] {'00537000000GePo'});
     Approval.process(pwr);

}
Raj VakatiRaj Vakati
one quick question .. 

Do you want to delete for one time or you need into the code 

Why can't you use the Mass Transfer Approval Requests ??
  1. From Setup, enter Mass Transfer Approval Requests in the Quick Find box, then select Mass Transfer Approval Requests.
  2. Search for the approval requests that you want to remove.
  3. Select Mass remove records from an approval process.
  4. Add comments.
  5. The comments you enter display on the Approval History related list.
  6. Select each approval request to remove from the approval process.
  7. Click Remove.
Raj VakatiRaj Vakati
Use this code
 
list<ProcessInstanceWorkitem> workItems = [SELECT Id,ProcessInstance.TargetObjectId,actorid,createddate,CreatedById
FROM ProcessInstanceWorkitem WHERE actorId = '00537000000GePo' and  
                                       ProcessInstance.Status = 'Pending' and 
                                       (createddate> 2018-01-01T01:00:00Z and createddate< 2018-04-30T01:00:00Z) ]; 

List<Approval.ProcessSubmitRequest> requests = new List<Approval.ProcessSubmitRequest> ();
	 for (ProcessInstanceWorkitem workItem: workItems) {
                  Approval.ProcessWorkitemRequest pwr = new Approval.ProcessWorkitemRequest();  
				pwr.setAction('Removed');
				pwr.setWorkItemId(workItem.id);
                requests.add(req1);

        }


      Approval.ProcessResult[] processResults = null;
                try {
                    processResults = Approval.process(requests, true)
    }catch (System.DmlException e) {
        System.debug('Exception Is ' + e.getMessage());
    }