ApexSensei

Drills DML operations

Savepoint and rollback

A savepoint marks a spot in the current transaction; Database.rollback undoes every DML made after it, with no Recycle Bin trace.

Your task

Insert a tagged Account after a savepoint, roll back, and prove the row is gone while the Id stays on the variable.

String tag = 'AS-ROLLBACK-' + UserInfo.getUserId() + '-' +
    String.valueOf(Datetime.now().getTime());
Savepoint checkpoint = Database.setSavepoint();
Account acct = new Account(Name = tag, Description = tag);

Requirements

  1. insert acct; should be present after the savepoint
  2. Database.rollback(checkpoint) should be present
  3. Before rollback: 1 should be printed
  4. After rollback: 0 should be printed
  5. Id still set: true should be printed
  6. Even in recycle bin: 0 should be printed

Sign in to open this drill