Transaction Control and Rollback
Chapter Topics
- What Is DML In Salesforce?
- Insert | APEX DML Standalone Statements
- Update | APEX DML Standalone Statements
- Upsert | APEX DML Standalone Statements
- Delete | Apex DML Standalone Statement
- Undelete | Apex DML Standalone Statement
- Merge | APEX DML Standalone Statements
- APEX DML Statements Best Practices
- Database Class in APEX
- Empty Recycle Bin
- Count Query | Method in Apex Database Class
- Lead Conversion | Method in Apex Database Class
- Transaction Control and Rollback
- Database Class Method Result Object
Savepoint setSavepoint():
Returns a savepoint variable that can be stored as a local variable which we can use with a rollback method to restore the database to that point.
Void rollback(Savepoint sp):
Restores the database to the state specified by the savepoint argument. Any emails submitted since the last savepoint are also rollbacked and not sent.
Savepoint sp1 = new Database.setSavepoint();
List < Account > accList = [SELECT name, phone FROM account WHERE name like‘ Acc % ’];
integer i = 1;
for (Account a: accList) {
A.phone = i + ’’;
i += 111;
}
update accList;
Savepoint sp2 = Database.setSavepoint();
for (Account b: accList) {
b.name = b.name + ’ss’;
}
update accList;
Savepoint sp3 = Database.setSavepoint();
if (roll = 1) Database.rollback(sp1);
else if (roll = 2) Database.rollback(sp2);
else if (roll = 3) Database.rollback(sp3);
Next Topic
Need more support?
Get a head start with our FREE study notes!
Learn more and get all the answers you need at zero cost. Improve your skills using our detailed notes prepared by industry experts to help you excel.