MilestoneTriggerTimeCalculator インターフェース
名前空間
マイルストーンの種別、ケースのプロパティ、およびケース関連オブジェクトに基づいてマイルストーンの動的なタイムトリガーを計算するには、Support.MilestoneTriggerTimeCalculator インターフェースを実装します。Support.MilestoneTriggerTimeCalculator インターフェースを実装するには、最初に implements キーワードでクラスを次のように宣言する必要があります。
1global class Employee implements Support.MilestoneTriggerTimeCalculator {
次に、クラスで次のメソッドの実装を提供する必要があります。
1global Integer calculateMilestoneTriggerTime(String caseId, String milestoneTypeId)実装されたメソッドは global または public として宣言する必要があります。
MilestoneTriggerTimeCalculator のメソッド
MilestoneTriggerTimeCalculator のインスタンスメソッドを次に示します。
calculateMilestoneTriggerTime(caseId, milestoneTypeId)
指定されたケースおよびマイルストーンタイプに基づいてマイルストーントリガー時間を計算し、その時間 (分単位) を返します。
構文
public Integer calculateMilestoneTriggerTime(String caseId, String milestoneTypeId)
パラメーター
- caseId
- 型: String
- マイルストーンが適用されるケースの ID。
- milestoneTypeId
- 型: String
- マイルストーンタイプの ID。
戻り値
型: Integer
計算されたトリガー時間 (分単位)。
MilestoneTriggerTimeCalculator の実装例
次のサンプルクラスは、Support.MilestoneTriggerTimeCalculator インターフェースの実装を示します。このサンプルでは、ケースの優先度とマイルストーン m1 によって、タイムトリガーが 18 分と決定されます。
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}次のテストクラスを使用して、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}