You need to sign in to do that
Don't have an account?
Anonymous Developer
Need Help creating apex action to unlock record
Here's my code
public class AS_UnlockApproval { @InvocableMethod (label = 'Unlock Record Brokerage Request' description = 'Unlock Brokerage Request Object' category = 'Brokerage Request') public static List<Response> Unlock(List<Request> requests) { List<Response> responseWrapper= new List<Response>(); for (Request i: requests) { String recordId = i.recordId; Approval.UnlockResult unlockResult = Approval.unlock(recordId); Response response = new Response(); response.isSuccess = unlockResult.isSuccess(); response.errors = packErrorString(unlockResult); responseWrapper.add(response); } return responseWrapper; } public static String packErrorString(Approval.UnlockResult unlockResult) { String errorString = ''; for(Database.Error err : unlockResult.getErrors()) { errorString = errorString + (' The following error has occurred.'); errorString = errorString + (' ' + err.getStatusCode() + ': ' + err.getMessage()); } return errorString; } public class InvocableErrorException extends Exception{} public class Request { @InvocableVariable public String recordId; } public class Response { @invocableVariable public Boolean isSuccess; @invocableVariable public String errors; } public class InvocableActionException extends Exception {} }
I already enabled the process automation on record locking and unlocking.
Am I missing something?
I just need to unlock the approval process automatedly since it's not editable. Need Help. Thanks.
Refer the below link.
https://www.biswajeetsamal.com/blog/set-approval-process-lock-and-unlock-records-using-apex-code/
Thanks!!