0

i have scenario like in a single transaction i am doing 2 DML operation. First one is delete,second one is update. If i get any issue while update the record , the deleted record should be reverted back (should be undeleted)

5

Yes, it will work for the delete DML operation. From the documentation Transaction Control:

Only when all the Apex code has finished running and the Visualforce page has finished running, are the changes committed to the database. If the request does not complete successfully, all database changes are rolled back.

With regards to the Savepoint statement:

Any DML statement that occurs after the savepoint can be discarded, and the database can be restored to the same condition it was in at the time you generated the savepoint.

It means that delete operation will be rolled back. In your code you have to make sure you use Database.rollback(sp); statement to rollback to the previous state.

| improve this answer | |

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.