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
Andreas MeyerAndreas Meyer 

Case Trigger won't fire when SlaExitDate is set by entitlement process

I like to do some additional calculation if the entitlement process is writing the Case.SlaExitDate field. Unfortunately the Case trigger won't fire if the entitlement process writes this field. Even in Case trigger UPDATE AFTER the SlaExitDate field is still null (i do a status change to "close" for that case, which is the stop criteria for the entitlement process as well, no milesstones are in the process). If i show the case again the SlaExitDate is set. So it seems that the update of that field done by the entitlement process happens outside any trigger context.
Any ideas?
ShashForceShashForce
Hi Andreas,

Seems strange. If you can post a snippet of your code, I can have a look.

Thanks,
Shashank
Andreas MeyerAndreas Meyer
Hi Shashank,

here is the code. Note that i used a helper class for trigger methods.

Tigger class:

trigger Case_Trigger on Case (before insert, before update, after update, after insert) {
.....
    if (trigger.isBefore && trigger.isUpdate) {
	
        Case_triggerMethods.assignCase_SLA_net_responsetime(Trigger.new, Trigger.oldMap);
		
        
     }
....
}

Case_triggerMethods class:


...

    public static void assignCase_SLA_net_responsetime(List<Case> newList, Map<Id,Case> oldMap){

	  
       for(Case c : newList) {
           if (null != c.EntitlementId && null != c.SlaStartDate && null != c.SlaExitDate) {
		        if (null != c.BusinessHoursId){
		        	long h_response_time = BusinessHours.diff(c.BusinessHoursId,c.SlaStartDate,c.SlaExitDate);
		        	if (null != h_response_time){
			        	c.SLA_net_response_time__c = h_response_time; 
		        	}
		        	else{
		        		c.SLA_net_response_time__c = 0;
		        	}
		        }
           }
       }
      
	 }

...

The SlaExitDate field is null whenever the trigger fires (i just removed all the system.debug calls). In fact it seems the entitlement process is setting the SlaExitDate field and the trigger won't fire at all. Setting the case to "close" is the exit criteria for the entitlement process. The change of case status will fire the trigger ... but the will be no additional trigger run after the entitlement process populates the field.

Before you ask: yes i moved the code to "rigger.isAfter && trigger.isUpdate", but the SlaExitDate field is null as well. If i refresh the case view after i closed the case the field is filled. 

Best,
Andreas

ShashForceShashForce
Hi Andreas,

It could be a similar issue to this but I'm not sure: https://success.salesforce.com/issues_view?id=a1p30000000SU70AAG

Anyway, as a workaround, for the trigger to work on case status change, annotate your method with "@future" to make it asynchronous and run in a near future, add a SOQL query in your future method to retrieve the cases whose Ids are part of Trigger.new, and process those records.

I am not sure if the same can be done when the entitlement process solely sets the slaExitDate, as I doubt whether this counts as a DML event for the trigger to fire.

Another option is to use scheduled apex to run a daily job.

Thanks,
Shashank
Andreas MeyerAndreas Meyer
Hi Shashank,

thanks for your time and efforts, i really appreciate this. The issue you meantioned is something different, so the only way for me is a workaround. Acually i set the case on "stopped" (Case field "IsStopped") to populate the Case StopStartDate date. Since i know the exit criterias of the entitlement process i am able to do that in the trigger code. Having the StopStartDate i am able to calculate the SLA net response time using the assigned BusinessHours set. Of course that will spoil the whole idea of configuable exit criterias using a entitlement process but it is the only way right now. I agree with you that setting the SlaExitDate isn't a DML event at all. a future function or a scheduled job isn't an alternative for me because of several reason but it might be a solution in another sceanrio of course.

What i really like to have is some kind of apex trigger for case/entitlement processes, so i am able to act as soon as the entitlement process is finished. But i guess we have to wait what SFDC will bring up in the future. In fact entitlement management is already flexible but out of the box i am able to name a couple of improvments to make it more flexible. On of them is to have more than one SlaStartDate/SlaExitDate since our cases can be re-opened if the customer sends a second email. To do that with milesstones is really a challenge and it makes it more complicated when it comes to reporting.

Anyway we are still in the evaluation process using entitlements versus a custom object to track SLA response times. And it seems a custom object will gives us more flexibility right now (just when it comes to SLA response time tracking of course).

Again.. thank you for your time.

Best,
Andreas