-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOmniChannelRoutingController.cls
55 lines (39 loc) · 1.59 KB
/
OmniChannelRoutingController.cls
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
50
51
52
53
54
55
public class OmniChannelRoutingController {
/*
Primary method to route records through Omni-Channel
*/
public static void routeToPreferredAgents( List < sObject > listRecords, String strEntity ) {
List < PendingServiceRouting > listPSRs = new List < PendingServiceRouting >();
String strChannelId = getChannelId( strEntity );
for ( sObject obj : listRecords )
listPSRs.add( createPendingServiceRouting( obj, strChannelId ) );
if ( listPSRs.size() > 0 ) {
insert listPSRs;
}
}
/*
Method to create Pending Service Routing record
*/
static PendingServiceRouting createPendingServiceRouting( sObject obj, String strChannelId ) {
PendingServiceRouting psrObj = new PendingServiceRouting(
CapacityWeight = 1,
IsReadyForRouting = true,
RoutingModel = 'MostAvailable',
RoutingPriority = 1,
ServiceChannelId = strChannelId,
WorkItemId = obj.Id,
PushTimeout = 0,
RoutingType = 'SkillsBased',
PreferredUserId = (String) obj.get( 'Preferred_User__c' ),
IsPreferredUserRequired = true
);
return psrObj;
}
/*
Method to get the Channel Id based on the Entity
*/
static String getChannelId( String strEntity ) {
ServiceChannel channel = [ SELECT Id From ServiceChannel Where RelatedEntity =: strEntity ];
return channel.Id;
}
}