0

Are all the records are locked for update during a Dml or only it's locked when we use 'For Update' in the query? If it's just when using a query with 'for update' then why Salesforce throws 'uncommitted work pending' error even when we don't use record lock before a call-out?

1
  • 3
    I'd edit your question with more specifics (ex. code that's throwing the error, the exact error message). You're talking about record lock but it sounds like you're having issues with a common error related to doing a DML before a callout in the same transaction as explained here. Commented Jun 13, 2020 at 19:17

2 Answers 2

4

The uncommitted work error will occur for things that you may not logically think as DML operations, including posting chatter messages, sending emails, publishing events, locking and unlocking records (approval process locks), setting a database savepoint for potential later rollback, scheduling a future, Batchable, Schedulable, or Queuable, etc. Simply querying records will not cause an uncommitted work error, even if you use FOR UPDATE. However, doing most other things that interact with the database will cause this error to occur.

1

The error 'uncommitted work pending' is not because of record lock instead it's because Salesforce does not allow Callout if there is any pending write operation on Database(the reason might be it does not want to hold write lock for long duration because callout response time depends on external system/service provider). Also in Apex, you cannot explicitly call database commit, its implicit though as per OoE.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .