Thursday 6 August 2020

Sample Apex class for Skill-based routing in Omni-Channel

Hi,

Skills-based routing uses Apex action classes to assign skills, priority, and the routing model to work items.

Here is a sample class:

It involves the following standard objects:
        
  • Case
  • PendingServiceRouting 
  • SkillRequirement 
  • ServiceChannel 
  • Skill 
global class SkillsBasedRoutingController { @InvocableMethod public static void routeUsingSkills(List<String> caseIdList) { List<Case> caseObjects = [SELECT Id, Description FROM
                Case WHERE Id in:caseIdList]; for (Case caseObj : caseObjects) { // Add SkillsBased PendingServiceRouting PendingServiceRouting psrObj = new PendingServiceRouting( CapacityWeight = 1, IsReadyForRouting = FALSE, RoutingModel = 'MostAvailable', RoutingPriority = 1, RoutingType = 'SkillsBased', ServiceChannelId = getChannelId('Service_Channel_Name'), WorkItemId = caseObj.Id ); insert psrObj; psrObj = [select id, IsReadyForRouting
            from PendingServiceRouting where id = : psrObj.id]; // Now add SkillRequirement(s) SkillRequirement srObj = new SkillRequirement( RelatedRecordId = psrObj.id, SkillId = getSkillId(caseObj.Description), SkillLevel = 5 ); insert srObj; // Update PendingServiceRouting as IsReadyForRouting psrObj.IsReadyForRouting = TRUE; update psrObj; } return; } public static String getChannelId(String channelName) { ServiceChannel channel = [Select Id From ServiceChannel Where DeveloperName = :channelName]; return channel.Id; } public static String getSkillId(String caseDescription) { String skillName = 'English'; if (caseDescription != null) { if (caseDescription.contains('Spanish')) { skillName = 'Spanish'; } else if (caseDescription.contains('French')) { skillName = 'French'; } } Skill skill = [Select Id From Skill Where DeveloperName = :skillName]; return skill.Id; } }
We can call this Apex class from the process builder as we implemented a method with "@InvocableMethod" annotation.


Reference:

No comments:

Post a Comment

How to include a screen flow in a Lightning Web Component

 Hi, Assume  you have a flow called "Quick Contact Creation" and API Name for the same is "Quick_Contact_Creation". To i...