MilestoneTriggerTimeCalculator Interface
Namespace
Implement the Support.MilestoneTriggerTimeCalculator
interface to calculate a dynamic time trigger for a milestone based on the milestone type, the
properties of the case, and case-related objects. To implement the Support.MilestoneTriggerTimeCalculator interface, you must
first declare a class with the implements keyword as
follows:
1public with sharing class Employee implements Support.MilestoneTriggerTimeCalculator {
Next, your class must provide an implementation for the following
method:
1public Integer calculateMilestoneTriggerTime(String caseId, String milestoneTypeId)The implemented method must be declared as global or public.
MilestoneTriggerTimeCalculator Methods
The following are instance methods for MilestoneTriggerTimeCalculator.
calculateMilestoneTriggerTime(caseId, milestoneTypeId)
Calculates the milestone trigger time based on the specified
case and milestone type and returns the time in minutes.
Syntax
public Integer calculateMilestoneTriggerTime(String caseId, String milestoneTypeId)
Parameters
-
caseId:
Type: String
ID of the case the milestone is applied to.
-
milestoneTypeId:
Type:
String ID of the milestone type.
Return Value
Type:
Integer The calculated trigger time in minutes.
MilestoneTriggerTimeCalculator Example Implementation
This sample class demonstrates the implementation of theSupport.MilestoneTriggerTimeCalculator interface. In this sample, the case’s priority and the milestone m1 determine that the time trigger is 18 minutes.
1global with sharing class myMilestoneTimeCalculator implements Support.MilestoneTriggerTimeCalculator {
2 global Integer calculateMilestoneTriggerTime(String caseId, String milestoneTypeId){
3 Case c = [SELECT Priority FROM Case WHERE Id=:caseId WITH USER_MODE];
4 MilestoneType mt = [SELECT Name FROM MilestoneType WHERE Id=:milestoneTypeId WITH USER_MODE];
5 if (c.Priority != null && c.Priority.equals('High')){
6 if (mt.Name != null && mt.Name.equals('m1')) { return 7;}
7 else { return 5; }
8 }
9 else {
10 return 18;
11 }
12 }
13}This test class can be used to test the implementation of Support.MilestoneTriggerTimeCalculator.
1@IsTest
2private with sharing class MilestoneTimeCalculatorTest {
3 @IsTest
4 static void testMilestoneTimeCalculator() {
5
6 // Select an existing milestone type to test with
7 MilestoneType[] mtLst = [SELECT Id, Name FROM MilestoneType WITH USER_MODE LIMIT 1];
8 if(mtLst.size() == 0) { return; }
9 MilestoneType mt = mtLst[0];
10
11 // Create case data.
12 // Typically, the milestone type is related to the case,
13 // but for simplicity, the case is created separately for this test.
14 Case c = new Case(priority = 'High');
15 insert as user c;
16
17 myMilestoneTimeCalculator calculator = new myMilestoneTimeCalculator();
18 Integer actualTriggerTime = calculator.calculateMilestoneTriggerTime(c.Id, mt.Id);
19
20 if(mt.name != null && mt.Name.equals('m1')) {
21 Assert.areEqual(7, actualTriggerTime);
22 }
23 else {
24 Assert.areEqual(5, actualTriggerTime);
25 }
26
27 c.priority = 'Low';
28 update as user c;
29 actualTriggerTime = calculator.calculateMilestoneTriggerTime(c.Id, mt.Id);
30 Assert.areEqual(18, actualTriggerTime);
31 }
32}