Created
January 16, 2015 21:11
-
-
Save dancinllama/354ade4c7ec79573ed90 to your computer and use it in GitHub Desktop.
Thou shalt not put queries in for loops (Bad example)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<Account> accList = new List<Account>([Select Id,Name From Account]); | |
for(Account acc : accList){ | |
Integer numWithEmail = 0; | |
for(Contact cont : [Select Id,Email From Contact Where AccountId = :acc.Id]){ | |
if(!String.isEmpty(cont.Email)){ | |
numWithEmail++; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment