Development questions
Does with sharing or without sharing on a Trigger Handler class affect SOQL and DML executed from the trigger?
Yes, for record sharing. with sharing makes SOQL return only records the running user can access and DML respect the user's edit access to records. without sharing ignores sharing rules. A class with no keyword inherits sharing from its caller (the trigger context is effectively system mode).
with sharing does not enforce object permissions or field-level security; use WITH USER_MODE or stripInaccessible for that.
Therefore a trigger handler declared with sharing can unexpectedly miss records (e.g. an Account the user can't see), so integration and roll-up logic often needs without sharing or inherited sharing deliberately.
apex-triggertriggersharingsecurity
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?