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