Where is Apex used?
As we have discovered, Apex code can run at any time for a variety of reasons, both in the foreground and background, and governor limits vary accordingly. You can read more about this in Apex Transactions and Governor Limits, from the Apex Developer Guide.
Occasionally, if you have some Apex code that is acting as a library of commonly used code, this code may need to act intelligently depending on the context it’s running in. For example, HTTP callouts are not allowed in Apex Triggers but are in almost all other cases. In order to avoid errors and take mitigating action, code can reference the Quiddity
enumeration. The following code can be used to obtain the current enumeration for the request currently being executed.
Quiddity currentType = Request.getCurrent().getQuiddity();
The following table lists the types of execution contexts that Apex code can be run from, their Quiddity
enumeration value, and considerations with respect to security...