Learn Apex
Trigger context variables
Triggers fire on insert, update, or delete — and each phase gives you different snapshots of the data. Pick a scenario; the grid shows what exists in Apex.
Context map

In Apex triggers, context variables tell you what changed. Trigger.new is always the incoming row list for insert/update; Trigger.oldMap shines on update/delete when you need the previous field values or the Id key. Start by naming the trigger after the object and event — your future self reads that faster than a generic name.

Operation:
Timing:
VariableAvailable?
Trigger.new

List of sObjects in the new state

Trigger.old

List of sObjects in the old state

Trigger.newMap

Map<Id, SObject> for new rows

Trigger.oldMap

Map<Id, SObject> for old rows

“no” means that variable is not part of this trigger event. “empty” here means before insert: rows exist in Trigger.new but Ids are not ready for a map yet — use Trigger.new in a loop instead.

Example trigger shape for this operation

Swap the operation in the first line — the body pattern matches what the context variables give you.

trigger AccountBeforeUpdate on Account (before update) {
    for (Account a : Trigger.new) {
        Account old = Trigger.oldMap.get(a.Id);
        if (a.Name != old.Name) {
            // field changed
        }
    }
}