I have old approval process in which there are 3 approval steps and I created new approval process entirely same as old approval except I removed one approval step and i deactivated old approval and activated new approval.whenever old records which are in locked state I am trying to approve means it was firing old approval process where as when I tested by creating a new record means there are no issues is there any idea how to achieve that old records which are in locked must use new approval process.
public static void sendPOCApproval(set<Id> setOppIds){
System.debug('sendPOCApproval Line 1');
List<Opportunity> listOpp =[SELECT Id, ownerid FROM Opportunity WHERE ID IN: setOppIds];
List<Approval.ProcessSubmitRequest> listOfApprovalRecords = new List<Approval.ProcessSubmitRequest>();
System.debug('sendPOCApproval Line 2');
if(!listOpp.isEmpty()){
System.debug('sendPOCApproval Line 3');
for(Opportunity opp : listOpp){
system.debug('opp.::');
System.debug('sendPOCApproval Line 4');
// Create an approval request for the opportunity
Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
req.setObjectId(opp.id);
System.debug('sendPOCApproval Line 5');
// Setting submitter of approval
req.setSubmitterId(opp.OwnerId);
System.debug('sendPOCApproval Line 6');
// Submit the record to specific process
req.setProcessDefinitionNameOrId('POC_approval');
System.debug('sendPOCApproval Line 7');
req.setSkipEntryCriteria(true);
//Adding approval requests to a list
listOfApprovalRecords.add(req);
System.debug('sendPOCApproval Line 8');
}
System.debug('sendPOCApproval Line 9');
// Submit the list of approval requests for the opportunity
if(!listOfApprovalRecords.isEmpty() && !Test.isRunningTest()){
System.debug('sendPOCApproval Line 10');
System.debug('listOfApprovalRecords.Size()'+listOfApprovalRecords.size());
List<Approval.ProcessResult> result = Approval.process(listOfApprovalRecords);
}
System.debug('sendPOCApproval Line 11');
}
System.debug('sendPOCApproval Line 12');
}