Using Quiddity to find out Apex execution context

It can be very useful in Apex execution context to find out from where the transaction has originated. For example it would possible to prevent executing certain code from the execute anonymous window or decide to run some code in with or without sharing context

You can get the current context like this:

Quiddity currentContext = Request.getCurrent().getQuiddity();

You can the do compare easily as follows:

if(Request.getCurrent().getQuiddity().equals(System.Quiddity.QUICK_ACTION)){
    //Do something
}

All possible Quiddity enum values

https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_enum_System_Quiddity.htm

Leave a comment