Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public map<Id,List<Contact>> accountmap= new map<id,List<Contact>>();
- List<Account> lstAccount = [SELECT Id, name, (SELECT Id, Name FROM Contacts) FROM Account];//you can filter here
- for(Account acc : lstAccount)
- {
- accountmap.put(acc.Id,acc.contacts.size());
- }
- for(Account ac:lstAccount){
- if(accountmap.containskey(ac.id){
- system.debug('contact size for each account-->'+accountmap.get(ac.id).size());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement