Assign Tasks to different members in a Queue using RoundRobin technique
Integer IntrandomNumber = Integer.valueof((Math.random() * 1000));
for{
Group grp = [SELECT Id, Name, Type, (SELECT Id, UserOrGroupId, GroupId FROM GroupMembers) FROM Group WHERE DeveloperName ='<Name_of_queue>' AND Type =: 'Queue' LIMIT 1];
if(grp != null && grp.GroupMembers != null && !grp.GroupMembers.isEmpty()){
Integer userIndex = Math.mod(IntrandomNumber, grp.GroupMembers.Size());
task.OwnerId = grp.GroupMembers.get(userIndex).UserOrGroupId;
}
IntrandomNumber = IntrandomNumber+1;
}
No comments:
Post a Comment