---
schema_version: "1"
id: c1ef25694fad0f86e069d726b95800b80655a047602815cb8cc11d605f2e86f0
title: MilestoneTriggerTimeCalculator Interface
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexref/apex_interface_support_milestonetriggertimecalculator.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_interface_support_milestonetriggertimecalculator.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: a442e50bf9fb0365b5a7936cbc8aea960be11006e4c290261e6a3d8c01293685
description: The Support.MilestoneTriggerTimeCalculator interface calculates the time trigger for a milestone.Calculates the milestone trigger time based on the specified case and milestone type and returns the time in minutes.
---
# MilestoneTriggerTimeCalculator Interface

The Support.MilestoneTriggerTimeCalculator interface calculates the time trigger for a milestone.

## Namespace

[Support](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_namespace_Support.htm "The Support namespace provides an interface used for Case Feed.")

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:

public with sharing class Employee implements Support.MilestoneTriggerTimeCalculator {

Next, your class must provide an implementation for the following method:

public Integer calculateMilestoneTriggerTime(String caseId, String milestoneTypeId)

The implemented method must be declared as global or public.

- **[MilestoneTriggerTimeCalculator Methods](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_interface_support_milestonetriggertimecalculator.htm#apex_Support_MilestoneTriggerTimeCalculator_methods)**
- **[MilestoneTriggerTimeCalculator Example Implementation](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_interface_support_milestonetriggertimecalculator.htm#apex_interface_support_milestonetriggertimecalculator_example)**

## MilestoneTriggerTimeCalculator Methods

The following are instance methods for MilestoneTriggerTimeCalculator.

- **[calculateMilestoneTriggerTime(caseId, milestoneTypeId)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_interface_support_milestonetriggertimecalculator.htm#apex_Support_MilestoneTriggerTimeCalculator_calculateMilestoneTriggerTime)**  
    Calculates the milestone trigger time based on the specified case and milestone type and returns the time in minutes.

### 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.

global with sharing class myMilestoneTimeCalculator implements Support.MilestoneTriggerTimeCalculator {   
     global Integer calculateMilestoneTriggerTime(String caseId, String milestoneTypeId){
        Case c = \[SELECT Priority FROM Case WHERE Id=:caseId WITH USER\_MODE\];
        MilestoneType mt = \[SELECT Name FROM MilestoneType WHERE Id=:milestoneTypeId WITH USER\_MODE\];
        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 with sharing class MilestoneTimeCalculatorTest {
    @IsTest
    static void testMilestoneTimeCalculator() {        
      
        // Select an existing milestone type to test with
        MilestoneType\[\] mtLst = \[SELECT Id, Name FROM MilestoneType WITH USER\_MODE 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 as user c;
        
        myMilestoneTimeCalculator calculator = new myMilestoneTimeCalculator();
        Integer actualTriggerTime = calculator.calculateMilestoneTriggerTime(c.Id, mt.Id);
        
        if(mt.name != null && mt.Name.equals('m1')) {
            Assert.areEqual(7, actualTriggerTime);
        }
        else {
            Assert.areEqual(5, actualTriggerTime);
        }
        
        c.priority = 'Low';
        update as user c;
        actualTriggerTime = calculator.calculateMilestoneTriggerTime(c.Id, mt.Id);
        Assert.areEqual(18, actualTriggerTime);
    }
}