Activity › Forums › Salesforce® Discussions › How is Trigger.New different from Trigger.newMap in Salesforce?
Tagged: Difference, Map in Salesforce, Mapping, Salesforce Custom Object, Trigger New, Trigger NewMap
-
How is Trigger.New different from Trigger.newMap in Salesforce?
Posted by Avnish Yadav on July 19, 2018 at 9:20 AMHow is Trigger.New different from Trigger.newMap in Salesforce?
Parul replied 7 years, 8 months ago 4 Members · 3 Replies -
3 Replies
-
Hello Avnish,
Trigger.New is simply a list of the records being processed by the trigger, so if all you need to do is loop through them then you can use that. It returns a list which is ordered. Suppose you have a custom object Custom_obj__c then Trigger.New is a list represented as List<Custom_obj__c>.
Trigger.newMap just allows you to target specific records by Id should you not need to process everything, or if you need to map other records back to these. It returns a map which is unordered. Trigger.newMap is a map represented as map<Id, Custom_obj__c>.
-
This reply was modified 7 years, 10 months ago by
shradha jain.
-
This reply was modified 7 years, 10 months ago by
shradha jain.
-
This reply was modified 7 years, 10 months ago by
- [adinserter block='9']
-
Hi,
To understand it more simple –
Trigger.new – it return the list of sobject’s records.
Trigger.newMap – It returns the map of Id vs sobject record.
Hope it helps.
-
Trigger.New is simply a list of the records being processed by the trigger. It returns a list which is ordered. Suppose you have a custom object Custom_obj__c then Trigger.New is a list represented as List<Custom_obj__c>.
Trigger.newMap just allows you to target specific records by Id should you not need to process everything. It returns a map which is unordered. Trigger.newMap is a map represented as map<Id, Custom_obj__c>.
Thanks
Log In to reply.