It seems like it should return a set instead, but it returns a list. Why is that?
- Anybody can ask a question
- Anybody can answer
- The best answers are voted up and rise to the top
There are several reasons for this:
Sets have Collisions
In a set, you can't have duplicate values. This means that if someone did this:
Trigger.new would contain only one entry in a before insert trigger.
Sets are Unordered
Trigger.new and Trigger.old are ordered in the same way, so that you can guarantee Trigger.new matches Trigger.old.
You wouldn't be able to compare old and new values directly without resorting to trigger.newmap and trigger.oldmap (which before insert would again have problems with).
You can't do this with a set:
A list is ordered, and it is very often useful to be able to compare the values of old and new during trigger processing, which you can do by comparing old[x] with new[x]