You need to sign in to do that
Don't have an account?
SF Beginner 2019
unlock all records in case using batch job
Hi can you revise my code if it is not correct wherein I want to update all case records wherein I will unlock all of them. I tested one record and its updating but I think when its all or bulk its not updating.
global class UnlockRecordBatchJob implements Database.batchable<sObject> { //Start of this batch job global Database.QueryLocator start(Database.BatchableContext BC) { String query = 'SELECT Id from Case Limit 2'; return Database.getQueryLocator(query); } //Exeution of batch job global void execute(Database.BatchableContext BC, List<Case> scope) { List<Case> caseList = [SELECT Id From CaseLimit 2]; //Check locked records List<Case> caseLockList = new List<Case>(); for(Case c : caseList) { if(Approval.isLocked(c.id)){ caseLockList.add(c); } } if(!caseLockList.isEmpty()){ //Unlock records List<Approval.UnlockResult> ulrList = Approval.unlock(caseLockList, false); // Iterate through each returned result for(Approval.UnlockResult ulr : ulrList) { if (ulr.isSuccess()) { //Operation was successful, so get the ID of the record that was processed System.debug('Successfully locked account with ID: ' + ulr.getId()); } else { //Operation failed, so get all errors for(Database.Error err : ulr.getErrors()) { System.debug('The following error has occurred.'); System.debug(err.getStatusCode() + ': ' + err.getMessage()); System.debug('Case fields that affected this error: ' + err.getFields()); } } } } } //finish job global void finish(Database.BatchableContext BC) { } }
The below should do. Please let me know if this solves your issue.
Thanks!
All Answers
The below should do. Please let me know if this solves your issue.
Thanks!