+ Start a Discussion
KaityKaity 

trigger.newMap.keySet()


Hi,

What is the significance of-   trigger.newMap.keySet()?

Opportunity i=[select ownerid, id,Owner.manager.email,Owner.manager.name from opportunity where id=:trigger.newMap.keySet()];

Thanks 
Kaity
AshlekhAshlekh
Hi,

In trigger if you try to call trigger.newMap.keySet() on update event or after insert it will return Id of records which is going to process.

In trigger if you try to call trigger.newMap.keySet() on before insert then it will return null.
Ramu_SFDCRamu_SFDC
+1 to Ashlekh, the below articles provide more information on trigger collection variables

http://developer.force.com/cookbook/recipe/comparing-queries-against-trigger-old-and-trigger-new
http://www.salesforcetutorial.com/salesforce-collections/
Pramod_SFDCPramod_SFDC
Hi,

I believe, the below link will provide you more insight.

>> http://www.iterativelogic.com/salesforce-apex-trigger-best-practices/

Regards
Pramod
David "w00t!" LiuDavid "w00t!" Liu
Trigger.newMap = a map of all records in your trigger. The key used in the map is the record ID, and the value is the record itself.
More info: http://www.sfdc99.com/2014/01/12/introduction-maps/

.keySet() is a method used on maps that returns all the keys of the map. Since the key in the map above is the record ID, you are returned a set of all IDs in your map.