Development questions
How do you enforce Object and Field-Level Security (FLS) in SOQL using WITH USER_MODE, WITH SYSTEM_MODE, or WITH SECURITY_ENFORCED?
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)).
soqlsecurityflsuser-mode
More Development questions
- What is an Apex Trigger in Salesforce and when should you use it over Flows?
- What is the difference between before triggers and after triggers?
- Explain all Trigger context variables (isInsert, isUpdate, isDelete, isUndelete, isBefore, isAfter, isExecuting, size, operationType).
- What is the difference between Trigger.new and Trigger.old?
- In which trigger events are Trigger.new and Trigger.newMap available?
- In which trigger events are Trigger.old and Trigger.oldMap available?