Created
August 27, 2022 03:13
-
-
Save sfboss/52b55edfa809b10619029d5559ad8292 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public with sharing class bCheckController { | |
@AuraEnabled | |
public static Boolean approveDC(Id theDCId){ | |
//Class used for Approving Record | |
try { | |
Approval.ProcessWorkitemRequest req = new Approval.ProcessWorkitemRequest(); | |
req.setComments('Approving request for DC'); | |
//Approve or Reject Record | |
req.setAction('Approve'); | |
//Getting Work Item Id | |
ProcessInstanceWorkitem pItem = [Select ID from ProcessInstanceWorkitem | |
WHERE ProcessInstance.TargetObjectId =: theDCId AND ActorId =: UserInfo.getUserId()]; | |
req.setWorkitemId(pItem.Id); | |
//req.setNextApproverIds = UserInfo.getUserId(); | |
// Submit the request for approval | |
Approval.ProcessResult result = Approval.process(req); | |
return true; | |
} catch (Exception e) { | |
system.debug (e.getStackTraceString() + e.getMessage()); | |
return false; | |
} | |
} | |
@AuraEnabled | |
public static Boolean rejectDC(Id theDCId, String comments){ | |
try { | |
Approval.ProcessWorkitemRequest req = new Approval.ProcessWorkitemRequest(); | |
req.setComments('Approving request for DC'); | |
//Approve or Reject Record | |
req.setAction('Reject'); | |
//Getting Work Item Id | |
ProcessInstanceWorkitem pItem = [Select Id from ProcessInstanceWorkitem | |
where ProcessInstance.TargetObjectId =: theDCId AND ActorId =: UserInfo.getUserId()]; | |
req.setWorkitemId(pItem.Id); | |
req.setComments(comments); | |
// Submit the request for approval | |
Approval.ProcessResult result = Approval.process(req); | |
return true; | |
} catch (Exception e) { | |
return false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment