fork download
  1. Map<Id, List<Contact>> accountToContacts = new Map<Id, List<Contact>>();
  2. // ... map population logic ...
  3. Id accId1 = '001000000000001AAA';
  4. List<Contact> list1 = new List<Contact>();
  5. list1.add(new Contact(LastName = 'Smith'));
  6. list1.add(new Contact(LastName = 'Jones'));
  7. accountToContacts.put(accId1, list1);
  8. Id accId2 = '001000000000002BBB';
  9. List<Contact> list2 = new List<Contact>();
  10. list2.add(new Contact(LastName = 'Brown'));
  11. accountToContacts.put(accId2, list2);
  12. for (Id accId : accountToContacts.keySet()) {
  13. // Inner loop to iterate over the List value
  14. for (Contact con : accountToContacts.get(accId)) {
  15. System.debug('Account ID: ' + accId + ' | Contact: ' + con.LastName);
  16. }
  17. }
  18.  
Success #stdin #stdout #stderr 0.01s 7752KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
./prog:1: expected expression