You need to sign in to do that
Don't have an account?
Trigger.new vs. Trigger.newMap
What is difference between Trigger.new and Trigger.newMap? The Apex Guide doesn't quite elaborate enough to make it clear.
Thanks,
Luke
Thanks,
Luke
function readOnly(count){ }
You need to sign in to do that
Don't have an account?
According to the docs, Trigger.new returns a list, which are ordered, and Trigger.newMap returns a map - which are unordered. The docs specifically state you should not rely on the ordering of a map's elements.
What to use depends on what you're doing - if you have an ID of an object you need to do something with, using the map makes more sense as you can use newMap.get(). Otherwise you'd have to loop over all the elements in Trigger.new and look for a matching ID. Similarly, if you have multiple loops over each item the trigger is operating on, the list returned by Trigger.new may be the better bet.
All Answers
How does my code limit me and in what scenarios is my code appropriate versus those scenarios where your use of maps is appropriate?
This may just be a best practice.
According to the docs, Trigger.new returns a list, which are ordered, and Trigger.newMap returns a map - which are unordered. The docs specifically state you should not rely on the ordering of a map's elements.
What to use depends on what you're doing - if you have an ID of an object you need to do something with, using the map makes more sense as you can use newMap.get(). Otherwise you'd have to loop over all the elements in Trigger.new and look for a matching ID. Similarly, if you have multiple loops over each item the trigger is operating on, the list returned by Trigger.new may be the better bet.