Home SALESFORCEConfiguration Skill Based Routing via Apex in Salesforce – Khyati Mehta

Skill Based Routing via Apex in Salesforce – Khyati Mehta

Skills-based routing looks at the skills required to complete a work item and matches these to the skills that are assigned to the agent. Omni-Channel routes the work to the first agent who has the required skills. Work items can have multiple skills, and agents can have multiple skills. If you want to route work by skills, you will have to use a setup flow to define mappings between work-item field values and skills. You have to basically create one skill mapping set for each object. In this video, we will understand step by step on how to configure skill based routing in our org.

Step by Step about Skill Based Routing via Apex in Salesforce:

  • 00:00 Introduction Skill Based Routing
  • 00:42 Enable Omni-Channel & Enable Skills-Based Routing  (Setup -> Omni-Channel -> Omni-Channel Settings)
  • 01:07 Create Service Channels (Case/Lead or any Custom Object)
  • 01:38 Create Skills (Setup -> Omni-Channel -> Skills)
  • 02:33 Create Service Resources  (From App Launcher -> Service Resources)
  • 03:09 Assign Skills to Services Resources ( From Service Resources -> Create a Skills from Related Tab)
  • 04:25 Create Presence Statuses & Assign the Status to Profile
  • 05:47 Create Apex Class logics to route the cases based on the Skills & Resources
  • 09:54 Call the Apex Class using Process Builder
  • 10:43 Demo – Skill Based Routing via Apex in Salesforce

public class SkillBasedRoutingDemoClass {
@InvocableMethod
public static void routingCasesToAgents(LIst<String> caseIds){
//Create PSR 
        //Add skills to the request for the case
        //Push it to queue
List<Case> casesInserted = [SELECT id,subject from Case where ID IN: caseIds];
LIst<Skill> allSkillsInDB = [SELECT id,MasterLabel from Skill];

for(Case caseRec : casesInserted){
PendingServiceRouting psr= new PendingServiceRouting();
psr.workItemId = caseRec.Id;
psr.RoutingType = ‘SkillsBased’;
psr.RoutingPriority = 1;
psr.CapacityWeight = 1;
psr.ServiceChannelId = ‘0N95g0000000FQz’; //USE YOUR OWN SERVICE CHANNEL ID
psr.RoutingModel = ‘MostAvailable’;
psr.IsReadyForRouting = FALSE; //DRAFT state
Insert psr; //DONE WITH MY FIRST STEP

//FIND OUT THE SKILLS REQUIRED FOR A GIVEN CASE BASED ON ITS SUBJECT
List<String> matchingSkillIds = new List<String>();
for(Skill skillRec: allSkillsINDB){
if(caseRec.Subject.contains(skillRec.MasterLabel)){
matchingSkillIds.add(skillRec.Id);
}
}

List<SkillRequirement> skillReqsToInsert = new List<SkillRequirement>();
//Associate matching skills with PSR request
for(String matchingSkillId: matchingSkillIds){
SkillRequirement skillRequ = new SkillRequirement();
skillRequ.SkillId = matchingSkillId;
skillRequ.RelatedRecordId = psr.id;
skillRequ.SkillLevel = 5;
skillReqsToInsert.add(skillRequ);
}
Insert skillReqsToInsert;

  //PUSH our request in to the queue
psr.IsReadyForRouting = TRUE;
Update PSR;
}
}
}

You may also like

Leave a Comment