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_MODEaccounts for polymorphic fields, such as Owner and Task.whatId.WITH USER_MODEprocesses all clauses in the SOQLSELECTstatement including theWHEREclause.WITH USER_MODEfinds all FLS errors in your SOQL query, whileWITH SECURITY_ENFORCEDfinds only the first error. Furthermore, in user mode, you can use thegetInaccessibleFields()method onQueryExceptionto 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];