Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save eddywebs/52080a1535f8014bae035dbd42cf9008 to your computer and use it in GitHub Desktop.
Save eddywebs/52080a1535f8014bae035dbd42cf9008 to your computer and use it in GitHub Desktop.
Thou shalt not put queries in loops (good example)
List<Account> accList = new List<Account>(
[Select
Id
,Name
,(Select
Email
From
Contacts
)
From Account]
);
for(Account acc : accList){
Integer numWithEmail = 0;
for(Contact cont : acc.Contacts){
if(!String.isEmpty(cont.Email)){
numWithEmail++;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment