Development questions

What is the difference between Trigger.new and Trigger.old?

DevelopmentEasyTCSWiproMindtree

Trigger.new is a list of the new versions of records (the values being saved). Trigger.old is a list of the old versions (values before the change).

  • Insert: only Trigger.new
  • Update: both; compare to detect field changes
  • Delete: only Trigger.old
  • Undelete: only Trigger.new

Trigger.new is editable in before triggers; Trigger.old is always read-only.

apex
for (Account a : Trigger.new) {
    Account oldA = Trigger.oldMap.get(a.Id);
    if (a.Phone != oldA.Phone) { /* phone changed */ }
}
apex-triggertriggercontext-variables