function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sherry pengsherry peng 

Does trigger.new is ordered?

Does anyone know whether the trigger.new is ordered or not? If yes, does trigger.old is the same oder of trigger.new? that is: trigger.new[0].id == trigger.old[0].id ?


Best Answer chosen by sherry peng
sherry pengsherry peng
In our organization, one of our class is dependent on the order of trigger.new. We wish they could always return the same order in every transaction. Unfortunately, after some testing, I find it is not always return the same order. For example, in a trigger, I will get all active users in current system, you could not expect the returned list<User> is in the same order. 

All Answers

Saurabh DhobleSaurabh Dhoble
Yes, trigger.new[0].id = trigger.old[0].id

BTw, I'm curious what you are trying to do here. Can you provide more details.
sherry pengsherry peng
In our organization, one of our class is dependent on the order of trigger.new. We wish they could always return the same order in every transaction. Unfortunately, after some testing, I find it is not always return the same order. For example, in a trigger, I will get all active users in current system, you could not expect the returned list<User> is in the same order. 
This was selected as the best answer