2

I am hoping if you can help clarify the rollback on transactions, for scenario below. For example if we have the piece of code below

MyCustomObject__c customObj = new MyCustomObject__c ();
Savepoint sp = Database.setSavepoint();
try{
   insert customObj;
}catch(Exception e){
  Database.rollback(sp);
}

if we have another user using the same app, and is submitting a save on a new Opportunity object at the same time as the above rollback is happening, would the rollback affect the Opportunity object being saved at same time or is it just on the customObject? Thanks

3
  • note in your example above, if the try block is only doing one DML operation, and it fails, no rollback is required. Rollback is typically used in the pattern you have when there are multiple DML operations within the try block and if any of them fail, all prior successful DMLs within the try{...} also need to rollback
    – cropredy
    Jan 29, 2015 at 1:05
  • thanks for the note @crop1645, I am doing multiple DML operations but my my code but this example was just short way to explain my question about other user actions happening sametime as rollback Jan 29, 2015 at 8:49
  • np, I made the comment more for others who might come across this post in the future
    – cropredy
    Jan 29, 2015 at 17:22

1 Answer 1

3

Any DML operations in the same transaction performed after Database.setSavePoint would be rolled back. This means that multiple users (and even the same user in multiple transactions) are isolated from each other, so the opportunity would be unaffected.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.