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

Perfect use cases to use trigger.newmap and trigger.oldmaps instead of trigger.new and trigger.old
Hi
can some one describe me some perfect use cases where trigger.newmap works instead of trigger.new and similarly where only trigger.oldmap works better than trigger.old
can some one describe me some perfect use cases where trigger.newmap works instead of trigger.new and similarly where only trigger.oldmap works better than trigger.old
According to the docs, Trigger.new returns a list, which are ordered, and Trigger.newMap returns a map - which are unordered.
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.
Here is one example.
Thanks,
Himanshu