+ 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.