You need to sign in to do that
Don't have an account?
Harish1234
savepoint and rollback?
hi,
Will any one helps me to give sample code with description where we wnat to go for savepoint and rollback with an real time example ..
Will any one helps me to give sample code with description where we wnat to go for savepoint and rollback with an real time example ..
Ankit Arora,
Please explain me clearly with an real time example where we can use savepoint and rollback?
All Answers
Case 1 : Unfortunately there was any error in creating child record(like user didn't fill required fields), but parent has been created successfully.
case 2 : User has filled the required information and clicked on save button again. So in this case there will be two parents created.
Now if you look into data base, there will be two parent records (from case one with no child and from case 2 with a child).
So case one could be avoided by using savepoint and rollback.
The syntax is to set the save point before any dml and then rollback to that savepoint when you face any error.
Another explaination :
Savepoint and roll back will help us to create your own transcation. Suppose you have written long code which contains many more DML statement, at the some point you will want this DML statement should not be executed, you may need to modify your code, at that time you will have to return that point, savepoint will identifies that point , Rollback will restore the database to that point(savepoint).
Here is some code you can refer
I picked these from this post : https://developer.salesforce.com/forums?id=906F000000092kUIAQ
Would recommend you to search in boards as many of the questions are already in here :)
Ankit Arora,
Please explain me clearly with an real time example where we can use savepoint and rollback?