Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. public map<Id,List<Contact>> accountmap= new map<id,List<Contact>>();
  2. List<Account> lstAccount = [SELECT Id, name, (SELECT Id, Name FROM Contacts) FROM Account];//you can filter here
  3. for(Account acc : lstAccount)
  4. {
  5. accountmap.put(acc.Id,acc.contacts.size());
  6. }
  7. for(Account ac:lstAccount){
  8. if(accountmap.containskey(ac.id){
  9. system.debug('contact size for each account-->'+accountmap.get(ac.id).size());
  10. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement