You need to sign in to do that
Don't have an account?

How a trigger determines whether a field has changed
If I have an "after insert" trigger, I can use something like the following to determine whether a particular field has changed:
Right?
If Trigger.old and Trigger.new have more than one record (because the trigger fired due to several records being changed at once), can I be certain that the records in Trigger.old and Trigger.new are always in the same order? In other words, can I assume that Trigger.old[x] and Trigger.new[x] refer to the same record?
Thanks,
Jeri
if (Trigger.old[0].myfield__c != Trigger.new[0].myfield__c) { // field changed } else { // field didn't change }
If Trigger.old and Trigger.new have more than one record (because the trigger fired due to several records being changed at once), can I be certain that the records in Trigger.old and Trigger.new are always in the same order? In other words, can I assume that Trigger.old[x] and Trigger.new[x] refer to the same record?
Thanks,
Jeri
All Answers
> Use Trigger.OldMap.<fieldName> and Trigger.NewMap.<fieldName> for their sequential comparison
To iterate over items in the maps, I need to index this somewhere -- could you please explain where?
Also, if I understand you correctly, this implies that I can expect Trigger.NewMap and Trigger.OldMap to be in order, but not necessarily Trigger.New and Trigger.Old. Why would that be the case?
Thanks again,
Jeri
http://www.salesforce.com/us/developer/docs/apexcode/index_CSH.htm#apex_triggers_bulk_idioms.htm
Trigger.new and Trigger.old are just arrays so they do preserve order relative to each other.
Jeri