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
Erik BurtonErik Burton 

PendingServiceRouting trigger not firing

Hello,

I'm trying to take advantage of the new CustomRequestedDatetime field on the PendingServiceRouting omni-channel object  to better prioritize our cases.  I made a trigger that would update that field, but for some reason it's not firing when a new PSR is created.  Even when the trigger is just this:
 
trigger Set_Custom_Requested_DateTime on PendingServiceRouting (before insert) {
    system.debug('Trigger fired');
}
Nothing shows in the debug log.  Here's a test case I was using to try to invoke and test the trigger:
 
@isTest
private class Set_Custom_Requested_DateTime_Test {

    static testMethod void myUnitTest() {
        Case cWithLOD = new Case();
        String subj1 = 'Test subject: ' + math.random();
        cWithLOD.Subject = subj1;
        Insert cWithLOD;
        // Find an omni-channel queue
        Group g = [SELECT ID FROM Group WHERE QueueRoutingConfigId != null LIMIT 1];
        cWithLOD = [SELECT Last_opened_date__c, ID, OwnerID FROM Case WHERE Subject = :subj1 LIMIT 1];            
        
        // Add case to that queue
        cWithLOD.OwnerId = g.ID;
        Update cWithLOD;
        PendingServiceRouting p = [SELECT ID, WorkItemID, CustomRequestedDateTime, CreatedDate FROM PendingServiceRouting WHERE WorkItemID = :cWithLOD.ID LIMIT 1];
        // Confirm that the trigger fired and the field changed
        System.assertEquals(p.CustomRequestedDateTime, cWithLOD.Last_opened_date__c, 'LOD didnt match');
    }
}
When running this test (or just manually creating cases and adding them to an omni-channel queue) the trigger never fires.

Thanks for your help!

 
Raj VakatiRaj Vakati
Looks like it's Object not supported before insert operation. I can able to see logs with the update 

 
trigger asdasd on PendingServiceRouting (after insert,before update , after update) {
System.debug('aaaaaaaaaaaaaa');
}

 
Raj VakatiRaj Vakati
https://developer.salesforce.com/docs/atlas.en-us.omni_channel_dev.meta/omni_channel_dev/sforce_api_objects_pendingservicerouting.htm
Vinod JakoreVinod Jakore
Hi,

To take advantage of the new CustomRequestedDatetime field on the PendingServiceRouting omni-channel object  to better prioritize  casesyou can write trigger on case as below:

trigger UpdateCasePSR on Case (before update) {
    LIST<PendingServiceRouting> List_PendingServiceRouting = new LIST<PendingServiceRouting>();
    List<Id> caseIds = new List<Id>{};
    for (Case theCase:trigger.new) 
        caseIds.add(theCase.Id);
    Map<Id,Case> MapOfCaseIdToCase = new Map<Id,Case> ();
    PendingServiceRouting[] pendingworkitems = new List<PendingServiceRouting>();
        for(PendingServiceRouting w : [Select Id, CustomRequestedDatetime, WorkItemId from PendingServiceRouting Where WorkItemId IN :caseIds And CustomRequestedDatetime = null]) {
            w.CustomRequestedDatetime = MapOfCaseIdToCase.get(w.WorkItemId).CreatedDate;
            pendingworkitems.add(w);
        }
        
        if(pendingworkitems.size() > 0)
            Database.update(pendingworkitems,false); 
}

In this scenario this should work!

Thanks!