Skip to main content
Tweeted twitter.com/StackSalesforce/status/1304208086467522561
Became Hot Network Question
edited title
Link
identigral
  • 7.8k
  • 34
  • 33
  • 45

Does Database.rollback on a savepoint release Select for Update locks?

Source Link
silverglass
  • 91
  • 1
  • 1
  • 6

Does Database.rollback release Select for Update locks?

I'm trying to understand Salesforce's locking mechanism. I ran a test which does the following:

  1. Calls Database.setSavepoint().
  2. Issues a Select for Update query.
  3. Calls Database.rollback(savepoint).
  4. Delays for several seconds.
  5. Exits the transaction.

I expected other threads to be able to access the record once step 3 competed. What I see is that while the changes to the record are rolled back by step 3, other threads cannot access the record until after step 5. In other words, while the changes may be rolled back, the locks aren't released.

Is this understanding correct? Is there any way for the locks to be released by the rollback?