Map<Id, Account> accountsById = new Map<Id, Account>([SELECT Id, Name FROM Account LIMIT 10]);
Set<Id> accountIds = accountsById.keySet();
Map<Id, Integer> numberOfContacts = new Map<Id, Integer>();
for (Account acc : [SELECT Id, Name, (SELECT Id FROM Contacts) FROM Account WHERE Id IN :accountIds]) {
numberOfContacts.put(acc.Id, acc.Contacts.size());
}
System.debug(numberOfContacts);
Sunday, December 3, 2017
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment