Saturday, July 13, 2019

How to dynamically determine Calling Context using Apex in Salesforce?

Hi All ,

we are using the multiple feature and Context (type) as per our requirement while writing Apex code.

Sample are:-

  • Batch
  • @future 
  • Queueable 
  • Schedulable 
  • Trigger 
  • Visualforce 
  • Apex REST 

so we can identify these context item in Apex code  as give way:-


  •  Batch - System.isBatch()
  • @future - System.isFuture()
  • Queueable - System.isQueueable()
  • Schedulable - System.isScheduled()
  • Trigger - Trigger.isExecuting
  • Visualforce - ApexPages.currentPage() != null
  • Apex REST - RestContext.request != null