Created
August 27, 2022 03:03
-
-
Save sfboss/95c54b1c4baa218810d007e9937a55ed 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 customApprovalsController { | |
@AuraEnabled | |
public static List<wrapperClass> getApprovals(String theType, String theCommentFilter){ | |
List<wrapperclass> theApprovals = getPendingList(theType, theCommentFilter); | |
return theApprovals; | |
} | |
@AuraEnabled | |
public static List<wrapperclass> getPendingList(String theType, String commentFilter) { | |
List<wrapperClass> theWrapList = new List<wrapperClass>(); | |
for (ProcessInstance pi: [SELECT Id, Status, TargetObjectId, TargetObject.Name, | |
(SELECT Id, ActorId, Actor.Name, OriginalActorId, OriginalActor.Name, StepStatus, Comments, ProcessNode.Name, CreatedDate FROM StepsAndWorkitems WHERE StepStatus =: 'Pending' AND ActorId = :UserInfo.getUserId()) | |
FROM ProcessInstance WHERE Status =: 'Pending' ORDER BY TargetObjectId] ) { | |
for (ProcessInstanceHistory pih : pi.StepsAndWorkItems) { | |
wrapperClass pendingApprovalWrap = new wrapperClass(); | |
pendingApprovalWrap.Status = pih.StepStatus; | |
pendingApprovalWrap.RecordName = String.valueOf(pi.TargetObject.Name); | |
pendingApprovalWrap.RecordId = String.valueOf(pi.TargetObjectId); | |
pendingApprovalWrap.RecordObject = String.valueOf(pi.TargetObjectId.getSObjectType()).split('__')[0]; | |
pendingApprovalWrap.AssignedToName = String.valueOf(pih.OriginalActor.Name); | |
pendingApprovalWrap.ApproverName = pih.Actor.Name; | |
pendingApprovalWrap.CreatedDate = String.valueOf(pih.CreatedDate); | |
pendingApprovalWrap.Comments = String.valueOf(pih.Comments); | |
String theObject = String.valueOf(pi.TargetObjectId.getSObjectType()).split('__')[0]; | |
system.debug('theObject :: ' + theObject); | |
system.debug('comment :: ' + commentFilter); | |
system.debug('theType :: ' + theType); | |
if (theType == null || theType == '' || theObject == theType) { | |
if ((commentFilter == '' || commentFilter == null) || (pendingApprovalWrap.Comments != null && pendingApprovalWrap.Comments.contains(commentFilter))) | |
theWrapList.add(pendingApprovalWrap); | |
} | |
} | |
} | |
return theWrapList; | |
} | |
public class wrapperClass{ | |
@AuraEnabled public String Status {get; set;} | |
@AuraEnabled public String RecordName {get; set;} | |
@AuraEnabled public String RecordId {get; set;} | |
@AuraEnabled public String RecordObject {get; set;} | |
@AuraEnabled public String AssignedToName {get; set;} | |
@AuraEnabled public String ApproverName {get; set;} | |
@AuraEnabled public String CreatedDate {get; set;} | |
@AuraEnabled public String Comments {get; set;} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment