In Salesforce Apex, getQuiddity() returns the Quiddity value of the current Request object. It can be used to find the Salesforce Apex current running context.
Sample Apex Class:
public class Utility {
public static void checkExecution() {
Request objReq = Request.getCurrent();
switch on objReq.getQuiddity() {
when ANONYMOUS {
System.debug(
'Anonymous Apex block'
);
}
when AURA {
System.debug(
'Aura component'
);
}
when BATCH_ACS {
System.debug(
'API Query Cursor driven batch Apex'
);
}
when BATCH_APEX {
System.debug(
'Batch Apex job'
);
}
when BATCH_CHUNK_PARALLEL {
System.debug(
'Chunks of a batch Apex job running in parallel'
);
}
when BATCH_CHUNK_SERIAL {
System.debug(
'Chunks of a batch Apex job running in serial'
);
}
when BULK_API {
System.debug(
'Bulk API request'
);
}
when COMMERCE_INTEGRATION {
System.debug(
'Apex integration for B2B Commerce'
);
}
when DISCOVERABLE_LOGIN {
System.debug(
'Login page used by external users to log in to an Experience Cloud site'
);
}
when EXTERNAL_SERVICE_CALLBACK {
System.debug(
'External Services asynchronous callback function'
);
}
when FUNCTION_CALLBACK {
System.debug(
'Callback function'
);
}
when FUTURE {
System.debug(
'Future method'
);
}
when INBOUND_EMAIL_SERVICE {
System.debug(
'Apex inbound email service'
);
}
when INVOCABLE_ACTION {
System.debug(
'Invocable Action'
);
}
when PLATFORM_EVENT_PUBLISH_CALLBACK {
System.debug(
'Apex publish callback for platform events'
);
}
when POST_INSTALL_SCRIPT {
System.debug(
'Managed package install or upgrade'
);
}
when QUEUEABLE {
System.debug(
'Queueable Apex operation'
);
}
when QUICK_ACTION {
System.debug(
'Quick Action'
);
}
when REMOTE_ACTION {
System.debug(
'Remote Action'
);
}
when REST {
System.debug(
'Apex RESTful Web service'
);
}
when RUNTEST_ASYNC {
System.debug(
'Apex tests running asynchronously'
);
}
when RUNTEST_DEPLOY {
System.debug(
'Apex tests run during deployment'
);
}
when RUNTEST_SYNC {
System.debug(
'Anonymous Apex block'
);
}
when SCHEDULED {
System.debug(
'Scheduled Apex job'
);
}
when SOAP {
System.debug(
'Apex SOAP Web service'
);
}
when SYNCHRONOUS {
System.debug(
'Synchronous Apex operation'
);
}
when TRANSACTION_FINALIZER_QUEUEABLE {
System.debug(
'Queueable job with transaction finalizers attached'
);
}
when VF {
System.debug(
'Visualforce page'
);
}
}
}
}
Sample Apex Code to test:
Utility.checkExecution();