I have a extension controller for my Visualforce Page. It has 2 Action methods, method1() and method2(). Each method executes DML statements.

if there is failure in method2(), I need to rollback the DMLs made by method1 ( as well as method2).

I am trying to use SavePoint as a class member because savepoint will be set in method1 and will be accessed in method2 for rollback.

creating a savepoint as class member requires it to be declared as "transient". If it is transient, the class level savepoint varialble is null, so the Database.rollback(sp) fails.

So does it mean it is not possible to have a savepoint as class member in extension controller ?

  • 1
    Savepoints can't exist across transactions, which is why they're forcibly transient. If you're calling method1(), and on completion of that, calling method2(), the transaction created in method1() has already committed to the database and can't be rolled back. I'm assuming there's some reason why you're splitting this into two transactions, but you may need to rethink the problem you're trying to solve. Have you already tried asking about the original problem? – sfdcfox Aug 14 '14 at 15:43
  • Saw a similar question that was posted awhile back in the developer forum with an in depth explanation: developer.salesforce.com/forums/… – Jenny B Aug 14 '14 at 15:48

You are correct this is not currently possible AFIAK as each execution of the methods in the controller are separate transactions and as you noted the Transient keyword is required.

You will have to write your own rollback if possible by storing the previous values in the controller as properties and updating them on failure in method 2.

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.