Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Thou shalt not put queries in for loops (Bad example)
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
You can’t perform that action at this time.