Home / apex / apex-stripinaccessible-and-fls-enforcement
apex-stripinaccessible-and-fls-enforcement
Use Security.stripInaccessible to enforce CRUD/FLS on user-supplied records before DML, and to scrub query results before returning them to clients. Covers AccessType.READABLE/CREATABLE/UPDATABLE/UPSERTABLE, the SObjectAccessDecision API, and when to prefer WITH USER_MODE on the SOQL itself. NOT for the with sharing / without sharing keyword choice — use apex/apex-with-without-sharing-decision. NOT for SOQL injection review — use apex/soql-security.
Open the skill folder on GitHub
Apex stripInaccessible and FLS Enforcement
Activate when Apex code accepts records from a less-privileged context (LWC, Aura, REST, Visualforce) and writes them to the database, OR when query results need to be scrubbed of fields the running user cannot read. Security.stripInaccessible(AccessType, records) removes inaccessible fields from a record collection and returns an SObjectAccessDecision you must operate on instead of the original list.
Before Starting
- Confirm the records are user-supplied. Internal trusted-context data (e.g., trigger handler reading from the trigger context with
without sharing) does not need stripInaccessible. - Decide the AccessType: are you reading, creating, updating, or upserting? The wrong enum will silently strip the wrong fields.
- Confirm the calling class's sharing keyword.
with sharingenforces record visibility; stripInaccessible enforces FIELD visibility. Both are needed for full enforcement. - Read the
apiVersionin the class's.cls-meta.xmlbefore judging what the surrounding code already enforces — that value is the gate, not the org's release. At 67.0+ (Summer '26) SOQL, SOSL, DML andDatabasemethods default to user mode and a class with no sharing keyword runswith sharing; at 66.0 and earlier both defaulted the other way, so a class pinned to 58.0 in a Summer '26 org keeps the old behaviour. Canonical table: