Change records (DML): Apex practice drills
Insert, update, upsert and delete, Database methods, save results, savepoints and bulk-safe DML.
9 drills · Intermediate · Free to read, run with Apex Path ($19/month after a 7-day trial)
- SObject field access (Beginner, 8 min)
Set and read Account fields with dot notation and dynamic SObject methods without saving a record. - Insert a tagged Account (Beginner, 10 min)
Insert one uniquely tagged Account and verify the saved record by its assigned Id. - Update a tagged Account (Beginner, 12 min)
Create one tagged Account, update its Description, and read the record before and after to prove the change. - Delete challenge-created records (Intermediate, 12 min)
Delete two tagged Accounts in one statement and prove they moved to the Recycle Bin. - Bulk update once (Intermediate, 15 min)
Prepare three tagged Accounts in a loop and update the collection with one DML statement. - Upsert: insert or update (Intermediate, 15 min)
Upsert one Account twice with Database.upsert and use isCreated() to show the first call inserts and the second updates. - Handle Database.SaveResult (Intermediate, 15 min)
Let one valid insert succeed while you read the status code of one invalid Account. - Savepoint and rollback (Intermediate, 15 min)
Insert a tagged Account after a savepoint, roll back, and show the row is gone while the Id stays on the variable. - Insert an Account with Contacts (Intermediate, 18 min)
Insert a parent Account, then its three Contacts in one list with AccountId set, and prove the link with a query.