Advertisement
Guest User

OmniChannel SkillsBased Trailheads

a guest
Apr 8th, 2020
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.89 KB | None | 0 0
  1. Global class SkillsBasedRouting {
  2.       @ InvocableMethod
  3.       public static void routeUsingSkills(List<String> cases) {
  4.            List<Case> caseObjects = [SELECT Id, Description FROM Case WHERE Id in :cases];
  5.  
  6.      for (Case caseObj : caseObjects) {
  7.          // Add SkillsBased PendingServiceRouting
  8.          PendingServiceRouting psrObj = new PendingServiceRouting(
  9.              CapacityWeight = 1,
  10.              IsReadyForRouting = FALSE,
  11.              RoutingModel  = 'MostAvailable',
  12.              RoutingPriority = 1,
  13.              RoutingType = 'SkillsBased',
  14.              ServiceChannelId = getChannelId('Service_Channel_Name'),
  15.              WorkItemId = caseObj.Id
  16.              );
  17.          insert psrObj;
  18.          psrObj = [select id, IsReadyForRouting from PendingServiceRouting where id = : psrObj.id];
  19.          
  20.          // Now add SkillRequirement(s)
  21.          SkillRequirement srObj = new SkillRequirement(
  22.              RelatedRecordId = psrObj.id,
  23.              SkillId = getSkillId(caseObj.Description),
  24.              SkillLevel = 5
  25.              );
  26.          insert srObj;
  27.          
  28.          // Update PendingServiceRouting as IsReadyForRouting
  29.          psrObj.IsReadyForRouting = TRUE;
  30.          update psrObj;
  31.      }
  32.      return;
  33.   }
  34.  
  35.   public static String getChannelId(String channelName) {
  36.       ServiceChannel channel = [Select Id From ServiceChannel Where DeveloperName = :channelName];
  37.       return channel.Id;
  38.   }
  39.  
  40.   public static String getSkillId(String caseDescription) {
  41.       String skillName = 'English';
  42.       if (caseDescription != null) {
  43.           if (caseDescription.contains('Spanish')) {
  44.               skillName = 'Spanish';
  45.           } else if (caseDescription.contains('French')) {
  46.               skillName = 'French';
  47.           }
  48.       }
  49.      
  50.       Skill skill = [Select Id From Skill Where DeveloperName = :skillName];
  51.       return skill.Id;
  52.   }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement