templates/ai-chat.html — interactive — ask something; every third answer fails on purpose ← back to docs
Why does my trigger hit governor limits? Apex basics · lesson 03
You

My trigger works on one record but fails when I data-load 200. I'm three lessons into Apex basics — explain what's happening, then give me a route to Platform Developer I.

Assistant

Your trigger is written for one record at a time. Salesforce hands a trigger up to 200 records in a single call, so anything you do inside the loop — a SOQL query, a DML statement — runs 200 times and blows the per-transaction limit (100 queries, 150 DML statements).

The fix is the same every time: query once before the loop into a Map, and collect changes into a List you insert once after it.

AccountTrigger.cls apex
// one query, outside the loopMap<Id, Account> parents = new Map<Id, Account>([SELECT Id, Rating FROM Account]);for (Contact c : Trigger.new) {  c.Description = parents.get(c.AccountId).Rating;}

Test it with 200 records, not one [1] — a test that inserts a single row proves nothing about the case that broke.

Covers this, in order

// Course Bulk-safe Apex patterns

Triggers that survive the 200-record data load.

9 lessons2h 10m
// Lesson Collections, maps and sets

The data structure that makes one query enough.

14:40Beginner
You

Good. Any project I could build and put on my resume?

Assistant

Drafting project ideas

Read your progress Searching projects

Three that map to what you have already built, hardest last. Each one is a real org artefact you can screenshot and talk through in an interview

Assistant
Apex basics · lesson 03 AccountTrigger.cls 4 KB
Enter to send · Shift+Enter for a new line

The assistant can be wrong. Check anything it says against the lesson it cites.