5

With the new Winter '21 release, salesforce makes it much easier to detect what is a current running context by means of Request.getCurrent().getQuiddity() method. This is great, thank you, salesforce.

//Get info about the current request
Request reqInfo = Request.getCurrent();

//Universally unique identifier for this request
//Same as requestId in splunk or REQUEST_ID in event monitoring
String currentRequestId = reqInfo.getRequestId();


//enum representing how Apex is running. e.g. BULK_API vs LIGHTNING
//Use this with a switch statement,
//instead of checking System.isFuture() || System.isQueueable() || ...
Quiddity currentType = reqInfo.getQuiddity();

There is a list of System.Quiddity enumeration, for example, ANONYMOUS, AURA, etc.

Apex Per-Transaction Governor Limits are divided into two parts: synchronous limit and asynchronous limit. Some of them are different, for example, total number of SOQL queries issued, maximum number of Apex jobs added to the queue with System.enqueueJob.

Finally, question. Is there any documentation, that could point, which enumeration is sync execution, and which is async?

2
  • Wouldn't SYNCHRONOUS, FUTURE, or QUEUEABLE provide the information you're looking for? – Kris Goncalves Dec 17 '20 at 12:57
  • @KrisGoncalves for most cases, that should be enough. but in making a managed package I need to cover all possible values. – Oleksandr Berehovskyi Dec 17 '20 at 13:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.