Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.
MilestoneTriggerTimeCalculator Interface
Namespace
1global class Employee implements Support.MilestoneTriggerTimeCalculator {1global 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)
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 class myMilestoneTimeCalculator implements Support.MilestoneTriggerTimeCalculator {
2 global Integer calculateMilestoneTriggerTime(String caseId, String milestoneTypeId){
3 Case c = [SELECT Priority FROM Case WHERE Id=:caseId];
4 MilestoneType mt = [SELECT Name FROM MilestoneType WHERE Id=:milestoneTypeId];
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 class MilestoneTimeCalculatorTest {
3 static testMethod void testMilestoneTimeCalculator() {
4
5 // Select an existing milestone type to test with
6 MilestoneType[] mtLst = [SELECT Id, Name FROM MilestoneType LIMIT 1];
7 if(mtLst.size() == 0) { return; }
8 MilestoneType mt = mtLst[0];
9
10 // Create case data.
11 // Typically, the milestone type is related to the case,
12 // but for simplicity, the case is created separately for this test.
13 Case c = new Case(priority = 'High');
14 insert c;
15
16 myMilestoneTimeCalculator calculator = new myMilestoneTimeCalculator();
17 Integer actualTriggerTime = calculator.calculateMilestoneTriggerTime(c.Id, mt.Id);
18
19 if(mt.name != null && mt.Name.equals('m1')) {
20 System.assertEquals(actualTriggerTime, 7);
21 }
22 else {
23 System.assertEquals(actualTriggerTime, 5);
24 }
25
26 c.priority = 'Low';
27 update c;
28 actualTriggerTime = calculator.calculateMilestoneTriggerTime(c.Id, mt.Id);
29 System.assertEquals(actualTriggerTime, 18);
30 }
31}