Request クラス
名前空間
使用方法
Request クラスを使用して、実行時に現在の Apex コンテキストを検出します。Request クラスのメソッドでは、現在の Apex 実行種別を表す一意の要求 ID と Quiddity 値を取得します。これらの値は、デバッグログやイベントログと関連付ける場合でも使用できます。
- 要求 ID は一意であり、要求によってトリガされたデバッグログを表します。
- 要求 ID と Quiddity 値は、イベントモニタリングで使用される Apex 実行イベント種別のイベントログファイルと同じです。
例
次のコード例は、現在の要求の要求 ID と Quiddity 値を取得することで現在の Apex コードコンテキストを取得する方法を示しています。
1//Get info about the current request
2Request reqInfo = Request.getCurrent();
3
4//Get the identifier for this request, which is universally unique
5//Same as requestId in splunk or REQUEST_ID in event monitoring
6String currentRequestId = reqInfo.getRequestId();
7
8//Enum representing how Apex is running. e.g. BULK_API vs LIGHTNING
9Quiddity currentType = reqInfo.getQuiddity();
10//Use this with a switch statement,
11//instead of checking System.isFuture() || System.isQueueable() || ...