Must be really simple but I am struggling with how to loop through this map. Gone through some examples but was unable to figure it out.
Question is, how to loop through user IDs from TargetActorMap map and check if they are in RMUserIDs list? Here is my code.
Map<Id, Id> TargetActorMap = new Map<Id, Id>();
Set<Id> userIds = new Map<Id, User>([select id from user where Approval_Level__c in ('RM', 'GM','DM')]).keySet();
for(ProcessInstance pi : [SELECT Id,TargetObjectId, (SELECT ID, StepStatus,TargetObjectId,ActorId
FROM StepsAndWorkitems where StepStatus = 'Pending'
and ActorId in :userIds order by CreatedDate desc limit 1)
FROM ProcessInstance where targetObjectId in :trigger.newMap.keySet()]) {
for(ProcessInstancehistory wi :pi.StepsAndWorkitems) {
TargetActorMap.put(pi.TargetObjectId, wi.ActorId);
}
}
Set<Id> RMUserIds = new Map<Id, User>([select id from user where Approval_Role__c = 'RM']).keySet();
for(ST_Orders__c s2 : [Select id,Approval_Status__c from ST_Orders__c where id in :TargetActorMap.keySet()]) {
if(s2.Approval_Status__c == 'Level 1 Approval'/* && User Level is not RM */ ) {
// S2.addError(System.Label.Approval_Error1);
}
else if(s2.Approval_Status__c != 'Level 1 Approval' /* && /*User Level is RM */) {
//S2.addError(System.Label.Approval_Error2);
}
}