Loading

Resolving Access Blocked Errors in Apex Test Classes with High Assurance Session Settings

Data pubblicazione: Mar 25, 2026
Descrizione

Use Case 1:

If the "Manage Data Export" policy in the Identity Verification settings is configured to High Assurance, Apex unit tests that schedule classes or batch jobs using System.schedule() or Database.scheduleBatch() may fail during deployments.
The error message observed in this scenario is "System.UnexpectedException: Access Blocked"
 

Use Case 2:

If the "Manage Permission Sets and Profiles" policy is set to Raise session to high assurance, Apex test classes that access Permission Sets or Profiles may fail with a NoAccessException.


Root Cause:

In these scenarios, the Apex test executes as a Standard session rather than a High Assurance session. As a result, access to certain operations requiring higher security levels is blocked, and Salesforce returns these errors.
Risoluzione

Workaround 1 (Temporary):

Change the "Manage Data Export" or "Manage Permission Sets and Profiles" policy from High Assurance to None.
 
***This approach is not recommended as a permanent solution, as it reduces the organization’s security settings. It can, however, be used temporarily to complete the deployment.
 

Workaround 2 (Recommended):

Set the session level to High Assurance in the session that initiates the Apex test, rather than within the Apex test itself.

Steps:
  1. Log in to Workbench: https://workbench.developerforce.com/login.php
  2. Navigate to Apex Execute and run the following command:
  3. Auth.SessionManagement.setSessionLevel(Auth.SessionLevel.HIGH_ASSURANCE);
  4. Go to Deploy and proceed with the metadata or test deployment.

Note: Steps 2 and 3 must be executed within the same session for the High Assurance level to apply.

Risorse aggiuntive

The setSessionLevel() command can also be executed via Salesforce CLI instead of Workbench, as long as the metadata deployment is initiated within the same elevated session.

Numero articolo Knowledge

005227573

 
Caricamento
Salesforce Help | Article