Thursday 27 February 2020

customize omni channel logic to distribute cases based on Case Creation Date

Omni Channel queues distributes cases, based on Date/Time the case is assigned to the queue.
we can customize this logic to look for some other attribute such as Case Creation Date.

Scenario : A new case is created and assigned to the Queue “A”. There were already 10cases in the queue. The newly cases when assigned to the queue is 11th in the queue. After the first 10 cases are distributed, the 11th case is pushed to the agent.
to over come from waiting time in Queue We can the distribute cases  based on Case Creation Date.

Source : https://developer.salesforce.com/docs/atlas.en-us.omni_channel_dev.meta/omni_channel_dev/sforce_api_objects_pendingservicerouting.htm
solution :

Object: PendingServiceRouting
field name : CustomRequestedDatetime
field  Description:  Retains the datetime of a work item’s initial request, so work items are rerouted using the datetime of the initial work request. When left blank, work items are rerouted using the datetime when they were rerouted.

in case trigger onAfterUpdate
we need to write future method or Queueableclass.


public static void ReprioritizeBasedonCreateddate(){
          List<PendingServiceRouting> lstPendingServiceRoutingtoupdate = new List<PendingServiceRouting>();
         Map<Id, PendingServiceRouting> routingByRoutingId = new Map<Id, PendingServiceRouting>();
         Set<id> CaseIds= new Set<id>();
         for(PendingServiceRouting objPendingService : [Select Id,QueueId, CustomRequestedDatetime, IsReadyforRouting, RoutingPriority, WorkItemId from PendingServiceRouting
                                                        where Queueid IN:'queue ids as per requirement'                                             
                                                        ]) {
             
             if(objPendingService.WorkItemid!=null){
                     if(objPendingService.WorkItemid.getSObjectType().getDescribe().getName()=='Case'){
                                    CaseIds.add(objPendingService.WorkItemid);
                                    routingByRoutingId.put(objPendingService.id, objPendingService);
                     } 
             }
       }
             Map<ID,Case> CaseMap=new  Map<ID,Case> ([select id,CreatedDate from Case where id in:CaseIds]);
             for(PendingServiceRouting objPendingService : routingByRoutingId.values()){
                        
                 if(CaseMap.containsKey(objPendingService.WorkItemid) && CaseMap.get(objPendingService.WorkItemid)!=null){
                     objPendingService.CustomRequestedDatetime  =CaseMap.get(objPendingService.WorkItemid).CreatedDate ;
                     
                     lstPendingServiceRoutingtoupdate.add(objPendingService);   
                 }
             }
               if(lstPendingServiceRoutingtoupdate.size()>0 && !lstPendingServiceRoutingtoupdate.isEmpty()){
                           List<Database.SaveResult> srs = Database.update(lstPendingServiceRoutingtoupdate, false);

              }

     }

No comments:

Post a Comment

customize omni channel logic to distribute cases based on Case Creation Date

Omni Channel queues distributes cases, based on Date/Time the case is assigned to the queue. we can customize this logic to look for some ...