Development questions
Write a SOQL query to retrieve Accounts ordered by Name in ascending order, locked for editing in Apex (FOR UPDATE), while enforcing User Mode permissions (WITH USER_MODE).
Place WITH USER_MODE after the WHERE clause and before ORDER BY, then add FOR UPDATE at the end.
apex
List<Account> accs = [SELECT Id, Name FROM Account WITH USER_MODE ORDER BY Name ASC FOR UPDATE];
This enforces the running user's object, field and sharing permissions while locking the returned rows for the rest of the transaction. Keep the transaction short to avoid UNABLE_TO_LOCK_ROW errors for others.
soqlscenariolockinguser-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?