Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.
Request Class
Namespace
Usage
Use the Request class to detect the current Apex context at runtime. The methods in the Request class obtain a unique request ID and the Quiddity value that represent the current Apex execution type. These values can also be used to correlate with debug and event logs.
- The request ID represents an individual transaction, but may not be universally unique. The request ID is present in the debug logs that are triggered by the request.
- The request ID and Quiddity values are the same as in the event log files of the Apex Execution event type used in Event Monitoring.
Example
This example code shows how to obtain current Apex code context by retrieving the request ID and Quiddity value of the current request.
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 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() || ...Request Methods
The following are methods for Request.
getQuiddity()
Signature
public System.Quiddity getQuiddity()
Return Value
Type: System.Quiddity
Uses the values from the Quiddity enum. This value identifies the type of execution event associated with the current request.