function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
jagdish nikam 9jagdish nikam 9 

trigger.newmap.keyset

Hi Team,

Could you please check below link?
https://developer.salesforce.com/page/Best_Practice:_Avoid_SOQL_Queries_Inside_FOR_Loops

In this link they used trigger.new.keyset in before insert event ( in a code where they used best practise). I read somewhere that if we use trigger.newmap.keyset in before insert then it will give null id's.

Could you please clarify my doubt?
Rahul KumarRahul Kumar (Salesforce Developers) 
Hi Jagdish,
  • In the trigger, if you try to call trigger.newMap.keySet() on update event or after inserting it will return Id of records which are going to process.
  • In the trigger, if you try to call trigger.newMap.keySet() on before insert then it will return null.
I hope it will be helpful.

Best Regards
RahulKumar
Sree SalesforceSree Salesforce
Before insert means  :-  Record was not inserted in salesforce . So We dont have Salesforce id.
User-added image
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_context_variables.htm
if ypou are not getting please let us know