You need to sign in to do that
Don't have an account?

PendingServiceRouting After Insert Trigger not firing
I am trying to use a PendingServiceRouting After Insert Trigger to manually create an AgentWork object to assign cases through Omni-Channel but it appears the trigger is not firing. I am able to create cases via Email-to-Case and query the PendingServiceRouting object, so I know it is being created. I am also able to call my code from Anonymous Apex, passing in the PendingServiceRouting object I created and it executes as expected.
Can anyone confirm that After Insert triggers can be used with PendingServiceRouting objects and/or offer some advice on how to proceed?
Can anyone confirm that After Insert triggers can be used with PendingServiceRouting objects and/or offer some advice on how to proceed?
trigger OnPendingServiceRoutingTrigger on PendingServiceRouting (after insert) { if (trigger.isAfter && trigger.isInsert) { System.debug('After Insert PendingServiceRouting Trigger'); PendingServiceRoutingTriggerHandler.afterInsert(trigger.newMap); } }
public class PendingServiceRoutingTriggerHandler { public static void afterInsert (Map<Id, PendingServiceRouting> NewPsr) { ... } }
I read: "Pay us more money or figure it out yourself." Anyway.....
Here is what I have learned during my adventure. First, "You can’t use external routing for skills-based routing." This was part of the error message I received when trying to create a PendingServiceRouting record with RoutingModel = 'ExternalRouting' and RoutingType = 'SkillsBased' So, if you are trying to use external routing, you must use queues. Second, I don't think the PendingServiceRouting After Trigger works. I also tried calling Apex from a Process Builder flow to no avail. As stated above, SF support is "not trained on triggers," so I wasn't able to get this officially confirmed but after days of trying, I don't think it is possible. Third, I have doubts as to whether AgentWork records can be created in Apex. Clearly, it must be possible to create them for external routing (with the API maybe?) but I don't know how. I would be grateful if anyone could offer some insight here.
Negatives aside, I was finally able to use skill-based routing in omni-channel to route a case by following the steps from Dan's link above. I plan to assign each of my support team members a unique skill. This will allow me to route cases to any uses I want to. (At least the first 2000, I think. That should be plenty.)
I would recommend that anyone needing a sophisticated method of routing cases to just modify the skill-based method as opposed to trying to create or update AgentWork records as I did. In theory, you should be able to assign a different skill to every agent which will allow you to route work to any possible combination of agents.
All Answers
When you use PendingServiceRouting objects for queue-based routing, the PendingServiceRouting objects don’t invoke before insert triggers.
Sharing rules aren’t supported with PendingServiceRouting even if the OwnerId field is enabled.
https://developer.salesforce.com/docs/atlas.en-us.omni_channel_dev.meta/omni_channel_dev/sforce_api_objects_pendingservicerouting.htm
Hey Jeff - I've just experienced the same problem this week whilst trying to implement a similar thing for External Routing. Can confirm that our After Insert trigger on PSR does not fire when initiating a Live Agent chat. Additionally, I've been unable to create a PSR in Anonymous Apex (or otherwise) as I receive this error ''FATAL_ERROR System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, field integrity exception: []' even when copying the code from Salesforce docs (https://help.salesforce.com/articleView?id=omnichannel_skills_based_routing_define_apex_action_class.htm&type=5). I foresee the inability to create a PSR via Apex being an issue when it comes to writing a legitimate test class too.
No response on my case with SF so far. Will post here if they come back with anything useful.
I read: "Pay us more money or figure it out yourself." Anyway.....
Here is what I have learned during my adventure. First, "You can’t use external routing for skills-based routing." This was part of the error message I received when trying to create a PendingServiceRouting record with RoutingModel = 'ExternalRouting' and RoutingType = 'SkillsBased' So, if you are trying to use external routing, you must use queues. Second, I don't think the PendingServiceRouting After Trigger works. I also tried calling Apex from a Process Builder flow to no avail. As stated above, SF support is "not trained on triggers," so I wasn't able to get this officially confirmed but after days of trying, I don't think it is possible. Third, I have doubts as to whether AgentWork records can be created in Apex. Clearly, it must be possible to create them for external routing (with the API maybe?) but I don't know how. I would be grateful if anyone could offer some insight here.
Negatives aside, I was finally able to use skill-based routing in omni-channel to route a case by following the steps from Dan's link above. I plan to assign each of my support team members a unique skill. This will allow me to route cases to any uses I want to. (At least the first 2000, I think. That should be plenty.)
I would recommend that anyone needing a sophisticated method of routing cases to just modify the skill-based method as opposed to trying to create or update AgentWork records as I did. In theory, you should be able to assign a different skill to every agent which will allow you to route work to any possible combination of agents.
I create a case, add myself to a queue, change the case owner to a queue, then open the case, expecting a PendingServiceRouting would be created first, followed by the creating of Agentwork when I open the case. But the connector receives nothing. If you can share with me any of your findings about PendingServiceRouting, I would be extremely grateful.