0

Has anyone worked with a high assurance session requirement and async apex?

I need to query the Security Health Check objects during an async process (the query happens in a queueable). If "View Health Check" is set to "Raise session to high assurance" on the Identity Verification page in the Setup menu, I get an error when trying to query the Security Health Check object: Requires Extra Verification

Using the SessionManagement class, I tried to:

  1. Use the generateVerificationUrl method to generate a verification url which raises session assurance level, and then start the queueable. The same issue occurred in the queueable making it seem like the high assurance session does not persist into an async action that the running user initiates.
  2. Use the setSessionLevel method to try and raise the session assurance level from Apex without user input. I tried this in both the controller which launches the queueable (outside of async apex) as well as in the queueable itself. When I use the setSessionLevel method inside a queueable, i get a gack every time. What is the correct way to perform an action which requires a high assurance session inside an async apex context?
5
  • setSessionLevel is the right incantation but what is a session in async context? Almost a philosophical question. Try calling out from your Queueable to your own code wrapped in an Apex REST service.
    – identigral
    Commented Aug 25, 2020 at 4:39
  • Thank you, @identigral. I gave it a go, but to no avail. Alas, I fear it's just not possible at this time. Commented Aug 26, 2020 at 19:10
  • A callout will work. You set the session level in your Apex REST service being called from Queuable and then execute whatever calls/tasks need higher assurance in that session.
    – identigral
    Commented Aug 26, 2020 at 19:23
  • Ohh, I see what you mean. I was only trying to set the session in the rest endpoint, and then do the work in my queueable. That would indeed work and be an acceptable workaround. Commented Aug 26, 2020 at 19:50
  • A footnote on session context in async jobs: it does exist. From the doc: UserInfo.getSessionId() returns the session ID only when the code is run by an active, valid user. When the code is run by an internal user, such as the automated process user or a proxy user, the method returns null
    – identigral
    Commented Sep 8, 2020 at 1:51

0

You must log in to answer this question.

Browse other questions tagged .