Debug it: Apex practice drills
Fix real production bugs: queries and DML in loops, null checks, recursion, mixed DML, empty tests and batch state.
8 drills · Intermediate · Free to read, run with Apex Path ($19/month after a 7-day trial)
- Fix a missing null check (Intermediate, 10 min)
A Lead trigger tidies email addresses, but one blank Email makes the whole insert fail. Read the error and fix it. - Fix a query that finds no rows (Intermediate, 10 min)
A lookup method works until an Account is missing, then throws List has no rows for assignment to SObject. Make it return null instead. - Fix a query inside a loop (Intermediate, 15 min)
A Contact trigger looks up each Account one at a time. It passes every test with 5 records and dies on a 200-record import. Bulkify it. - Fix DML inside a loop (Intermediate, 15 min)
An Opportunity trigger creates a follow-up Task per record with insert inside the loop. It fails at 151 records. Collect first, insert once. - Fix a test that checks nothing (Intermediate, 15 min)
A test class is green, yet a wrong total and a missing error both slip through. Add the asserts that make it fail when the code is wrong. - Stop a trigger calling itself (Advanced, 15 min)
Closing one Case now fails with maximum trigger depth exceeded. The after-update handler updates the Case, which runs the handler again. Break the loop. - Fix a mixed DML error (Advanced, 20 min)
Onboarding creates an Account and a User in one method. In production that throws MIXED_DML_OPERATION. Move the User insert into its own transaction. - Fix a Batch job that forgets its count (Advanced, 20 min)
An archive Batch counts what it changes, but its finish report always says 0. Find out why the counter resets and fix it.