-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcaseRoundRobinAssignment.java
More file actions
49 lines (48 loc) · 2.11 KB
/
caseRoundRobinAssignment.java
File metadata and controls
49 lines (48 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
public class caseRoundRobinAssignment{
public static Boolean runOnce = false;
public static Boolean runMerge = false;
public static void assignTicketsRoundRobin(Set<Id> ticketIdsSet){
/* get list of all the tickets */
List<Case> ticketList = [Select Id, OwnerId, Case__c FROM Case Where Id IN:ticketIdsSet];
Integer index;
Integer ticketNumber;
Integer agentSize;
List<User> agentList = new List<User>();
Set<Id> queueIdsSet = new Set<Id>();
System.debug('#### ticketList = '+ticketList);
// Fetch Ids of the group.
For(Case c : ticketList){
If(String.valueOf(c.ownerId).startsWith('00G')){
queueIdsSet.add(c.ownerId);
}
}
// return if Case is already assigned to user
If(queueIdsSet==null || queueIdsSet.size()==0)return;
System.debug('#### queueIdsSet = '+queueIdsSet);
Set<Id> userIdsSet = new Set<Id>();
// Fetch Ids of the users
For(GroupMember gm : [Select Id, UserOrGroupId FROM GROUPMEMBER WHERE GroupId IN : queueIdsSet]){
userIdsSet.add(gm.UserOrGroupId);
}
System.debug('#### userIdsSet = '+userIdsSet);
/* fetch the total no of users for RRD that are active */
agentList = [Select Id, Name, Profile.Name From User Where Id In : userIdsSet AND ISACTIVE = true];
// return if there are no active users
If(agentList==null || agentList.size()==0)return;
System.debug('#### agentList = '+agentList);
For(Case c : ticketList){
if(c.Case__c!=null){
ticketNumber = Integer.valueOf(c.Case__c);
System.debug('#### ticketNumber = '+ticketNumber);
agentSize = agentList.size();
index = Math.MOD(ticketNumber ,agentSize);//+1;
System.debug('#### index = '+index);
c.OwnerId = agentList[index].id;
}
}
If(ticketList!=null && ticketList.size()>0){
System.debug('#### Updating tickets = '+ticketList);
update ticketList;
}
}
}