BusinessHours クラス
BusinessHours メソッドを使用して、カスタマーサポートチームが活動する営業時間を設定します。
名前空間
BusinessHours のメソッド
BusinessHours のメソッドは次のとおりです。すべてのメソッドが静的です。
add(businessHoursId, startDate, intervalMilliseconds)
開始時の datetime からの間隔を追加して、営業時間のみを辿ります。結果の datetime をローカルタイムゾーンで返します。
署名
public static Datetime add(String businessHoursId, Datetime startDate, Long intervalMilliseconds)
パラメーター
戻り値
型: Datetime
isWithin(businessHoursId, targetDate)
指定された目標日が営業時間内にある場合、true を返します。休日は計算に含まれます。
署名
public static Boolean isWithin(String businessHoursId, Datetime targetDate)
戻り値
型: Boolean
例
次の例では、指定された時間がデフォルトの営業時間内にあるかどうかを調べています。
1// Get the default business hours
2BusinessHours bh = [SELECT Id FROM BusinessHours WHERE IsDefault=true];
3
4// Create Datetime on May 28, 2013 at 1:06:08 AM in the local timezone.
5Datetime targetTime = Datetime.newInstance(2013, 5, 28, 1, 6, 8);
6
7// Find whether the time is within the default business hours
8Boolean isWithin= BusinessHours.isWithin(bh.id, targetTime);nextStartDate(businessHoursId, targetDate)
指定された目標日以降の、次に営業時間が開始する日付を返します。指定された目標日が営業時間内にある場合、この目標日が返されます。
署名
public static Datetime nextStartDate(String businessHoursId, Datetime targetDate)
戻り値
型: Datetime
例
次の例では、目標日以降で、次に営業時間が再開する日付を調べています。目標日が所定の営業時間内にある場合、その目標日が返されます。返される時間は、ローカルタイムゾーンの時間になります。
1// Get the default business hours
2BusinessHours bh = [SELECT Id FROM BusinessHours WHERE IsDefault=true];
3
4// Create Datetime on May 28, 2013 at 1:06:08 AM in the local timezone.
5Datetime targetTime = Datetime.newInstance(2013, 5, 28, 1, 6, 8);
6// Starting from the targetTime, find the next date when business hours reopens. Return the target time.
7
8// if it is within the business hours. The returned time will be in the local time zone
9Datetime nextStart = BusinessHours.nextStartDate(bh.id, targetTime);