According to the documentation,
Trigger.old
andTrigger.oldMap
are only available inupdate
anddelete
Triggers.Are these variables
null
otherwise, or are they just empty? WouldTrigger.old.isEmpty()
returntrue
if it’s referenced in aninsert
Trigger?
Answer
Trigger.Old is null in a Before Trigger and will therefore throw a NullPointerException for any reference / method invocation on it.
16:08:40.060 (60355000)|USER_DEBUG|[2]|DEBUG|**** Trigger.old null
16:08:40.060 (60362000)|SYSTEM_METHOD_EXIT|[2]|System.debug(ANY)
16:08:40.060 (60503000)|FATAL_ERROR|System.NullPointerException:
Attempt to de-reference a null object
Attribution
Source : Link , Question Author : Matt K , Answer Author : techtrekker