[SalesForce] Dynamically create time trigger for warning and violation in milestone

While creating a milestone in entitlement process we specify warning and violation time statically. I have a custom date field in Case. The milestone should enter in warning state only when the current day is 1 day before that custom date field. And milestone should enter in violation state when the current day is 1 day past the custom date. So, I need to specify the warning and violation time dynamically. How to do this dynamically?

Best Answer

If I can understand your question correctly, the milestone duration (in minutes) will be based on the difference of Custom Datetime field and current system date.

So, you need to create a apex class which implements Support.MilestoneTriggerTimeCalculator and here you will calculate the duration of that milestone.

global class myMilestoneTimeCalculator implements Support.MilestoneTriggerTimeCalculator {   
     global Integer calculateMilestoneTriggerTime(String caseId, String milestoneTypeId){
        Case c = [SELECT CustomDateField__c FROM Case WHERE Id=:caseId];
        return ((c.CustomDateField__c.getTime()/1000/60) - (System.Now().getTime()/1000/60))              
     }
}

Specify the apex class name selecting the lookup field in the milestone configuration as follows:

Milestone config

The Warning and Violation is easy to configure. Specify 1 day before and 1 day after respectively in those sections.

Related Topic