ApexSensei

All drills

DML operations: Apex practice drills

Insert, update, upsert and delete, Database methods, save results, savepoints and bulk-safe DML.

Intermediate · Check and Run with Apex Path ($19 a month).

  1. SObject field access Beginner · 8 min

    Use dot notation when you know the field while you write the code.

  2. Insert a tagged Account Beginner · 10 min

    insert saves a new record and writes the new Id back onto the same variable.

  3. Update a tagged Account Beginner · 12 min

    update saves changed fields on a record that already has an Id.

  4. Delete challenge-created records Intermediate · 12 min

    delete removes records by Id.

  5. Bulk update once Intermediate · 15 min

    Bulk-safe Apex changes records inside a loop and saves them all with one DML after the loop.

  6. Upsert: insert or update Intermediate · 15 min

    upsert inserts when no match exists and updates when one does.

  7. Handle Database.SaveResult Intermediate · 15 min

    Database.insert(records, false) turns on partial success: it returns one SaveResult per record instead of throwing.

  8. Savepoint and rollback Intermediate · 15 min

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

  9. Insert an Account with Contacts Intermediate · 18 min

    A child record needs its parent's Id, so the parent Account is inserted before its Contacts.

  10. Catch a DmlException and read its details Intermediate · 14 min

    Default DML is all-or-none, so one bad row throws DmlException.

  11. Undelete from the Recycle Bin Intermediate · 12 min

    delete moves a row to the Recycle Bin; undelete restores it with the same Id.

  12. Roll back parent and children on a child failure Intermediate · 15 min

    One savepoint before the first DML, one rollback inside the catch, and the whole step vanishes.

  13. Merge duplicate Accounts Intermediate · 14 min

    Database.merge(master, duplicate) keeps the master, deletes the duplicate, and moves related children to the master.

Start practicing free