Skip to main content
added 15 characters in body
Source Link
Sachin Hooda
  • 1.7k
  • 10
  • 12

Converting comment from @identigral to an answer for completeness of the OP's question & future readers.

Starting Winter 21 this indeed is possible to determine the calling context of the request with System.Request class. The Request class provides a few methods among them we do have a method that returns an enum(System.Quiddity) specifying the context of origin of this request.

Request reqInfo = Request.getCurrent(); System.Quiddity cxt = reqInfo.getQuiddity(); 

It can be wrapped inside a nice little switch case or a class that implements Callable interface & a call method having a different logic has to be executed based on the calling context.

Request reqInfo = Request.getCurrent(); switch on reqInfo.getQuiddity(){ when VF { // Visualforce } when AURA { // Lightning Component } when INVOCABLE_ACTION { // Flow/Process Builder } when ANONYMOUS { // execute anonymous } when REST { // RESTful } when FUTURE, SCHEDULED, QUEUEABLE, BATCH_APEX { // A few Async context } } 

There are more Quiddity context & the entire list is described here.

Converting comment from @identigral to an answer for future readers.

Starting Winter 21 this indeed is possible to determine the calling context of the request with System.Request class. The Request class provides a few methods among them we do have a method that returns an enum(System.Quiddity) specifying the context of origin of this request.

Request reqInfo = Request.getCurrent(); System.Quiddity cxt = reqInfo.getQuiddity(); 

It can be wrapped inside a nice little switch case or a class that implements Callable interface & a call method having a different logic has to be executed based on the calling context.

Request reqInfo = Request.getCurrent(); switch on reqInfo.getQuiddity(){ when VF { // Visualforce } when AURA { // Lightning Component } when INVOCABLE_ACTION { // Flow/Process Builder } when ANONYMOUS { // execute anonymous } when REST { // RESTful } when FUTURE, SCHEDULED, QUEUEABLE, BATCH_APEX { // A few Async context } } 

There are more Quiddity context & the entire list is described here.

Converting comment from @identigral to an answer for completeness of the OP's question & future readers.

Starting Winter 21 this indeed is possible to determine the calling context of the request with System.Request class. The Request class provides a few methods among them we do have a method that returns an enum(System.Quiddity) specifying the context of origin of this request.

Request reqInfo = Request.getCurrent(); System.Quiddity cxt = reqInfo.getQuiddity(); 

It can be wrapped inside a nice little switch case or a class that implements Callable interface & a call method having a different logic has to be executed based on the calling context.

Request reqInfo = Request.getCurrent(); switch on reqInfo.getQuiddity(){ when VF { // Visualforce } when AURA { // Lightning Component } when INVOCABLE_ACTION { // Flow/Process Builder } when ANONYMOUS { // execute anonymous } when REST { // RESTful } when FUTURE, SCHEDULED, QUEUEABLE, BATCH_APEX { // A few Async context } } 

There are more Quiddity context & the entire list is described here.

Source Link
Sachin Hooda
  • 1.7k
  • 10
  • 12

Converting comment from @identigral to an answer for future readers.

Starting Winter 21 this indeed is possible to determine the calling context of the request with System.Request class. The Request class provides a few methods among them we do have a method that returns an enum(System.Quiddity) specifying the context of origin of this request.

Request reqInfo = Request.getCurrent(); System.Quiddity cxt = reqInfo.getQuiddity(); 

It can be wrapped inside a nice little switch case or a class that implements Callable interface & a call method having a different logic has to be executed based on the calling context.

Request reqInfo = Request.getCurrent(); switch on reqInfo.getQuiddity(){ when VF { // Visualforce } when AURA { // Lightning Component } when INVOCABLE_ACTION { // Flow/Process Builder } when ANONYMOUS { // execute anonymous } when REST { // RESTful } when FUTURE, SCHEDULED, QUEUEABLE, BATCH_APEX { // A few Async context } } 

There are more Quiddity context & the entire list is described here.