+ Start a Discussion

How to find out if code is running from time-based workflow?

I have a code that calls Auth.SessionManagement.getCurrentSession()
Session is not available in asynchronous processes and the code throws 
unexpected exception that can't  be caught.

System.UnexpectedException: Current session unavailable Class.Auth.SessionManagement.getCurrentSession:

I can preven't the code from this situation by checking the execution context. (System.isBatch(), isFuture ect)But I'm having problems because of time-based workflow that executes field updates and runs the trigger. The system.isScheduled() detects only scheduled apex. Is there a way to prevent my code from running into the check and throwing an exception?