+ Start a Discussion

using savepoint in extension controller

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 ?
NehalNehal (Salesforce Developers) 

Please refer to links below which will give you sample code on how to use savepoint in apex class:


Also there are certain limitations of Savepoint which are listed below:

>>Each savepoint you set counts against the governor limit for DML statements.
>>Static variables are not reverted during a rollback. If you try to run the trigger again, the static variables retain the values from the first run.
>>Each rollback counts against the governor limit for DML statements. You will receive a Runtime error if you try to rollback the database additional times.
>>The ID on an sObject inserted after setting a savepoint is not cleared after a rollback.

I hope this answers your query.

" I hope this information has been helpful. If this has helped resolve your issue, please let us know by marking the post as "Best Answer" to help others in the community with similar questions. "