# How do you enforce Object and Field-Level Security (FLS) in SOQL using WITH USER_MODE, WITH SYSTEM_MODE, or WITH SECURITY_ENFORCED?

**Topic:** Soql · **Difficulty:** Medium · **Asked at:** Salesforce, Deloitte, EY, KPMG · **Tags:** soql, security, fls, user-mode

Read it on the site: https://www.forcechallenges.com/interview-questions/how-do-you-enforce-object-and-field-level-security-fls-in-soql-using-with-user-mode-with-system-mode-or-with

## Answer

Apex runs in system mode by default, so enforce user permissions explicitly:

- `WITH USER_MODE`: enforces the user's object permissions, FLS and sharing rules; errors if inaccessible fields are queried.
- `WITH SYSTEM_MODE`: explicitly run in system mode (ignores FLS/CRUD; sharing follows class declaration).
- `WITH SECURITY_ENFORCED`: older; checks object and field access of fields in SELECT, throws exception.

```apex
List<Account> accs = [SELECT Id, Name FROM Account WITH USER_MODE];
```
Prefer `USER_MODE`, which also enforces filters and works with DML (`Database.insert(records, AccessLevel.USER_MODE)`).

---
Source: ForceChallenges · last updated 2026-10-21
