The WITH SECURITY_ENFORCED SOQL Clause is Removed

To run a SOQL or SOSL query in user mode, use the WITH USER_MODE clause instead of the WITH SECURITY_ENFORCED clause. Apex classes set to API version 67.0 and later that include WITH SECURITY_ENFORCED don’t compile.

Where: This versioned change applies to API version 67.0 and later. The change applies to Lightning Experience and Salesforce Classic in Enterprise, Performance, Unlimited, and Developer editions.

Why: WITH USER_MODE replaces WITH SECURITY_ENFORCED because of these additional advantages.

  • WITH USER_MODE accounts for polymorphic fields, such as Owner and Task.whatId.
  • WITH USER_MODE processes all clauses in the SOQL SELECT statement including the WHERE clause.
  • WITH USER_MODE finds all FLS errors in your SOQL query, while WITH SECURITY_ENFORCED finds only the first error. Furthermore, in user mode, you can use the getInaccessibleFields() method on QueryException to examine the full set of access errors.

How: To avoid compilation errors in API version 67.0 and later, replace all instances of WITH SECURITY_ENFORCED in your code with WITH USER_MODE.

Account acc = [SELECT Id FROM Account WHERE Name = 'Singha' WITH USER_MODE LIMIT 1];