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
Suresh RaghuramSuresh Raghuram 

help with for loop structure

for(Lead lead: leads)

 

what the each lead is representing

 

For(Lead lead: tigger.new)

 

I want know the difference

 

thanks

Best Answer chosen by Admin (Salesforce Developers) 
craigmhcraigmh

In the first example, the "leads" variable is a collection of Leads sObjects that you've declared previously.

 

In the second example, you're looping through a collection of sObjects inside of a trigger, and assuming that it's a trigger on the Lead sObject, since you're implicitly casting each sObject as a Lead.