global class Employee implements Support.MilestoneTriggerTimeCalculator {
global Integer calculateMilestoneTriggerTime(String caseId, String milestoneTypeId)
The implemented method must be declared as global or public.
The following are instance methods for MilestoneTriggerTimeCalculator.
public Integer calculateMilestoneTriggerTime(String caseId, String milestoneTypeId)
Type: Integer
The calculated trigger time in minutes.
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.
global class myMilestoneTimeCalculator implements Support.MilestoneTriggerTimeCalculator { global Integer calculateMilestoneTriggerTime(String caseId, String milestoneTypeId){ Case c = [SELECT Priority FROM Case WHERE Id=:caseId]; MilestoneType mt = [SELECT Name FROM MilestoneType WHERE Id=:milestoneTypeId]; if (c.Priority != null && c.Priority.equals('High')){ if (mt.Name != null && mt.Name.equals('m1')) { return 7;} else { return 5; } } else { return 18; } } }
This test class can be used to test the implementation of Support.MilestoneTriggerTimeCalculator.
@isTest private class MilestoneTimeCalculatorTest { static testMethod void testMilestoneTimeCalculator() { // Select an existing milestone type to test with MilestoneType[] mtLst = [SELECT Id, Name FROM MilestoneType LIMIT 1]; if(mtLst.size() == 0) { return; } MilestoneType mt = mtLst[0]; // Create case data. // Typically, the milestone type is related to the case, // but for simplicity, the case is created separately for this test. Case c = new Case(priority = 'High'); insert c; myMilestoneTimeCalculator calculator = new myMilestoneTimeCalculator(); Integer actualTriggerTime = calculator.calculateMilestoneTriggerTime(c.Id, mt.Id); if(mt.name != null && mt.Name.equals('m1')) { System.assertEquals(actualTriggerTime, 7); } else { System.assertEquals(actualTriggerTime, 5); } c.priority = 'Low'; update c; actualTriggerTime = calculator.calculateMilestoneTriggerTime(c.Id, mt.Id); System.assertEquals(actualTriggerTime, 18); } }