• Erik Burton
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 1
    Replies
We use Email-to-Case to create and update cases from customer emails.  Currently, whenever a reply comes in to an old closed case, it always reopens the old case (if the email has the case's RefID in it).  Instead, we'd like to be able to use business rules to determine whether an inbound email referencing an old case reopens that case or creates a new case.

To do this, I'm planning to use process builder to apply business rules to newly created incoming EmailMessage objects.  If it detects a reply that should be linked to a new case, rather than reopening the old case, it would pass that EmailMessage to an invocable apex class (or possibly a flow), which would clone that incoming email, create a new case, and link the two together.  All of that seems pretty straightforward.

However, I would also like the invocable apex (or flow) to be able to delete the original email message, so it is not associated with the original parent case.  Is that also possible?  Or is that initiating object inaccessible (or undeletable) by the invoked code?

Thanks for your help!
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!

 
I'm making my first trigger, and I think I must be missing something basic.  This is a trigger that detects whether the owner of a closed case is an omni-channel queue, and if it is it reassigns it to the last person who modified the case instead.  The ownership change happens successfully in the trigger, but isn't being applied as part of the update itself.

Simplified code:
Trigger ReassignOCClosedCases on Case (before insert, before update) {
   for (Case c : Trigger.new) {
    	//Check if the case is closed and owned by an omni-channel queue.
    	system.debug('ReassignOCCC triggered for: ' + c.Subject);  
    	if (c.Status == 'Closed') {
    		set<ID> sOCQueues = new set<ID>();
    		List<Group> gOCQueues = [SELECT ID, Name FROM Group WHERE QueueRoutingConfigID != '' ];
    		for(Group g : gOCQueues) {
			    	sOCQueues.add(g.ID);    
		}
    		//Check if the current queue is OC-controlled
    		if(sOCQueues.contains(c.OwnerID)) {
	    		// if it is, reassign to the person who last modified the case
	    		c.OwnerID = c.LastModifiedByID;
	    		system.debug('ROCCC: OwnerID is now ' + c.OwnerID);
    		}
    	}
    }
}
And a much abbreviated version of the test class:
@isTest
private class TestReassignOCClosedCases {

    static testMethod void myUnitTest() {

//Creates a queue group called gOCTestQueue, with a routing configuration and queue attached [removed for length]

        case cTestA = new case(Status ='New', Priority = 'Medium', Origin = 'Email', Subject = 'Test1 starts open then is closed', OwnerId = gOCTestQueue.ID);
        insert cTestA;

        cTestA.status = 'Closed';
        system.debug('About to update after closing.  OwnerID = ' + cTestA.OwnerID);
        update cTestA;
        system.debug('Updated after closing.  OwnerID = ' + cTestA.OwnerID);
        system.assertNotEquals(cTestA.OwnerID, gOCTestQueue.ID);
}
The debug log will then show:
|DEBUG|About to update after closing.  OwnerID = QUEUEIDSTRING and testQueueID = QUEUEIDSTRING
|DEBUG|ROCCC: OwnerID is now USERIDSTRING
|DEBUG|Updated after closing.  OwnerID = QUEUEIDSTRING
and the AssertNotEquals fails.

What am I missing here, is there a reason the record change isn't being applied as part of the update?  Thanks for your help!
 

I'm new to Visualforce and could use some guidance to know whether this is even possible, and if so in which direction I should start exploring.

I'm trying to make  "Previous cases" page that'll be used within the case view, that shows a list of all previous cases associated with the same contactID.  I think I've got a good handle on how to show those cases using a Standard List Controller, but the result is totally non-interactive.

Is there a way to generate a list where a user can click on an entry to open that object in a new tab?  I'm hoping there's another controller out there which I've just missed so far.

Thanks for your help!

I have a scheduled apex class that automatically adds and removes users from particular queues at different times during the day.  However, to have these queue membership changes reflected omni-channel, the agents need to set themselves to offline, then available (or away) again.

I would like to automate this for them, by logging an agent out after I've updated their queue membership.  However, I cannot find a way to log an agent out of omni-channel through Apex.  I cannot delete a UserServicePresence object, nor can I update the "IsCurrentStatus" field of that object.

There is a handy api call available in the console integration toolkit (https://developer.salesforce.com/docs/atlas.en-us.api_console.meta/api_console/sforce_api_console_logout.htm) but that would require VisualForce instead, and a completely different implementation approach.

Has anyone else found a way to set an agent's presence status through Apex?  Thanks!
I'm making my first trigger, and I think I must be missing something basic.  This is a trigger that detects whether the owner of a closed case is an omni-channel queue, and if it is it reassigns it to the last person who modified the case instead.  The ownership change happens successfully in the trigger, but isn't being applied as part of the update itself.

Simplified code:
Trigger ReassignOCClosedCases on Case (before insert, before update) {
   for (Case c : Trigger.new) {
    	//Check if the case is closed and owned by an omni-channel queue.
    	system.debug('ReassignOCCC triggered for: ' + c.Subject);  
    	if (c.Status == 'Closed') {
    		set<ID> sOCQueues = new set<ID>();
    		List<Group> gOCQueues = [SELECT ID, Name FROM Group WHERE QueueRoutingConfigID != '' ];
    		for(Group g : gOCQueues) {
			    	sOCQueues.add(g.ID);    
		}
    		//Check if the current queue is OC-controlled
    		if(sOCQueues.contains(c.OwnerID)) {
	    		// if it is, reassign to the person who last modified the case
	    		c.OwnerID = c.LastModifiedByID;
	    		system.debug('ROCCC: OwnerID is now ' + c.OwnerID);
    		}
    	}
    }
}
And a much abbreviated version of the test class:
@isTest
private class TestReassignOCClosedCases {

    static testMethod void myUnitTest() {

//Creates a queue group called gOCTestQueue, with a routing configuration and queue attached [removed for length]

        case cTestA = new case(Status ='New', Priority = 'Medium', Origin = 'Email', Subject = 'Test1 starts open then is closed', OwnerId = gOCTestQueue.ID);
        insert cTestA;

        cTestA.status = 'Closed';
        system.debug('About to update after closing.  OwnerID = ' + cTestA.OwnerID);
        update cTestA;
        system.debug('Updated after closing.  OwnerID = ' + cTestA.OwnerID);
        system.assertNotEquals(cTestA.OwnerID, gOCTestQueue.ID);
}
The debug log will then show:
|DEBUG|About to update after closing.  OwnerID = QUEUEIDSTRING and testQueueID = QUEUEIDSTRING
|DEBUG|ROCCC: OwnerID is now USERIDSTRING
|DEBUG|Updated after closing.  OwnerID = QUEUEIDSTRING
and the AssertNotEquals fails.

What am I missing here, is there a reason the record change isn't being applied as part of the update?  Thanks for your help!