0

I can't seem to create a PendingServiceRouting record related to a SocialPost via apex. I can create PendingServiceRouting records related to cases, we've been doing this for a while.

When executing this code as an anonymous block, using a Case Id for WorkItemId value, and a channel setup for the case object, I get my expected result; a record created and the case routed.

Id serviceChannelId = [SELECT Id FROM ServiceChannel WHERE DeveloperName = 'casesChannel'].Id;
insert new PendingServiceRouting(
    CapacityWeight = 1,
    IsReadyForRouting = true,
    RoutingModel = 'MostAvailable',
    RoutingPriority = 1,
    RoutingType = 'SkillsBased',
    ServiceChannelId = serviceChannelId,
    WorkItemId = '5008A000006oVvqQAE',
    CustomRequestedDateTime = System.now()
);

When executing this code, using a SocialPost Id for WorkItemId value, and a channel setup for the SocialPost object, I get a pretty clear error.

Id serviceChannelId = [SELECT Id FROM ServiceChannel WHERE DeveloperName = 'Social'].Id;
insert new PendingServiceRouting(
    CapacityWeight = 1,
    IsReadyForRouting = true,
    RoutingModel = 'MostAvailable',
    RoutingPriority = 1,
    RoutingType = 'SkillsBased',
    ServiceChannelId = serviceChannelId,
    WorkItemId = '0ST8A0000001cJ3WAI',
    CustomRequestedDateTime = System.now()
);

Gets this error:

System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, You can create skills-based Pending Service Routing records only for Cases, Leads, Orders and Custom Objects.: [WorkItemId]

So I change my RoutingType value, and my code looks like this:

Id serviceChannelId = [SELECT Id FROM ServiceChannel WHERE DeveloperName = 'Social'].Id;
insert new PendingServiceRouting(
    CapacityWeight = 1,
    IsReadyForRouting = true,
    RoutingModel = 'MostAvailable',
    RoutingPriority = 1,
    RoutingType = 'QueueBased',
    ServiceChannelId = serviceChannelId,
    WorkItemId = '0ST8A0000001cJ3WAI',
    CustomRequestedDateTime = System.now()
);

I get this error:

System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, field integrity exception: []

This error is entirely unhelpful, so I've been trying all kinds of things to make this work. My only assumption is that my new RoutingType value of QueueBased doesn't work with one of my other values. I tried the easy comment out each one at a time and see what happens. Exact same error every time. There is not a whole lot of documentation around the PendingServiceRouting object. Has anyoneone experienced this issue and solved it?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.