Why does A work but not B? For B I receive the error: "Variable does not exist: Contacts".
A
List<Account> accts = [SELECT id, (SELECT id FROM CONTACTS) FROM Account];
List<Contact> cons = new List<Contact>();
for(Account a : accts) {
for(Contact con : a.Contacts) {
cons.add(con);
}
}
system.debug(accts);
system.debug(cons);
B
List<Account> accts = [SELECT id, (SELECT id FROM CONTACTS) FROM Account];
List<Contact> cons = accts.Contacts;
system.debug(accts);
system.debug(cons);