The Quiddity Enum stands out as
a highly valuable but often overlooked feature, offering one of the most
effective means to grasp the context of Apex execution. Leveraging Quiddity
allows us to discern whether an Apex method is invoked from Lightning Web
Components (LWC), Aura, or an Anonymous context. Explore the comprehensive
documentation linked below to discover the full range of contexts supported by
Quiddity.
Below is the Example of Quiddity.
public List<Account> getAccountsWithQuiddityGuard(){
List<Account> accounts = new List<Account>();
public static List<Quiddity> allowedQuiddities = new List<Quiddity>{
Quiddity.QUEUEABLE,
Quiddity.BATCH_APEX,
Quiddity.RUNTEST_ASYNC,
Quiddity.RUNTEST_SYNC
};
Quiddity q = System.Request.getCurrent().getQuiddity();
if(allowedQuiddities.contains(q)){
accounts = [Select ID from Account];
} else{
accounts = [Select Id from Account with SECURITY_ENFORCED];
}
return accounts;
}
The Request class is
under System namespace in apex. Request.getCurrent().getQuiddity()
type is Quiddity — a enum which can hold the following values
🔹ANONYMOUS
🔹 AURA
🔹 BATCH_APEX
🔹 BATCH_CHUNK_PARALLEL
🔹 BATCH_CHUNK_SERIAL
🔹 BULK_API
🔹 FUNCTION_CALLBACK
🔹 FUTURE
🔹 QUEUEABLE
🔹 REST
🔹 SCHEDULED
🔹 SOAP
🔹 SYNCHRONOUS
🔹 VF
Reference:
DEMO:
Comments
Post a Comment
Please Write your comment here.