function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jeff Hutchinson 17Jeff Hutchinson 17 

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?
 
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) {

    ...

    }
}


 
Best Answer chosen by Jeff Hutchinson 17
Jeff Hutchinson 17Jeff Hutchinson 17
I opened a case with SF as well. Here's what they had to say.
Hi Jeff,

Thanks for taking my call.

As discussed over call you mentioned that you are trying a different workaround to achieve this functionality.

I am checking this with my experts and will consult the. As this involves trigger so we might not able to assist you as we are not trained on triggers.

Developer support is currently available only to our premier customers and premier partners. We apologize for any impact this may be having on you. 

We support our standard customers through the developer support boards at https://developer.salesforce.com/. If you have a developer support question, are looking for technical documentation, practices, code samples and other ways to speed your development time.

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

Raj VakatiRaj Vakati
PendingServiceRouting  is support after trigger .. can you  start printing line by lines and see where is stopping .. its very difficult to track 

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
Jeff Hutchinson 17Jeff Hutchinson 17
Thanks for the quick response. I'm not able to print any debugging information. I have set trace flags on myself, the trigger, and automated processes and noting prints to the log. Also, the code executes perfectly in Anonymous Apex, which is what leads me to believe the trigger is not firing. I have read the documentation at the link you provided many times and it has been of no help.
DanWareing1DanWareing1

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.

Jeff Hutchinson 17Jeff Hutchinson 17
I opened a case with SF as well. Here's what they had to say.
Hi Jeff,

Thanks for taking my call.

As discussed over call you mentioned that you are trying a different workaround to achieve this functionality.

I am checking this with my experts and will consult the. As this involves trigger so we might not able to assist you as we are not trained on triggers.

Developer support is currently available only to our premier customers and premier partners. We apologize for any impact this may be having on you. 

We support our standard customers through the developer support boards at https://developer.salesforce.com/. If you have a developer support question, are looking for technical documentation, practices, code samples and other ways to speed your development time.

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.
This was selected as the best answer
DanWareing1DanWareing1
Hey Jeff - Salesforce today (yes, today) confirmed that this is a 'documentation bug'. The product is working 'as expected', but the documentation is wrong. Apologies for not having better news for you. I wish I could help suggest reasonable alternatives, but we haven't been given any by Salesforce and don't have any useful ideas yet ourselves.
Jeff Hutchinson 17Jeff Hutchinson 17
Hi Dan, thanks for the follow-up. I filed a case too but since we're not premier customers they wouldn't do anything for us. I'm not sure about your requirements but perhaps you can use skill-based routing? I was able to follow the steps at https://help.salesforce.com/articleView?id=omnichannel_skills_based_routing_setup.htm&type=5 and use this as a workaround. Not being able to use queues was severe over-kill for what I needed, but it worked. Best of luck!
robin patpatiarobin patpatia
Jeff\Dan, I was also looking into this, the use case is very different. We want to replicate, how Liveagent sends the chat notification to all the online agent instead of specific Agent. Any suggestions?
Jeff Hutchinson 17Jeff Hutchinson 17
I'm not sure I am reading that correctly. Are you trying to send the notification to all of your agents? If not, what exactly are you trying to do?
wailok tam 7wailok tam 7
I am running in a related issues in setting up external routing. I set up a push topic for PendingServiceRouting following this guide (https://developer.salesforce.com/docs/atlas.en-us.omni_channel_dev.meta/omni_channel_dev/omnichannel_external_routing_integrate.htm).
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.