Load Account Contacts
A parent-to-child subquery pulls Accounts and their Contacts in one SOQL.
Your task
Load the two tagged Accounts and their Contacts with one query that uses a Contacts subquery.
String tag = 'AS-Q307-' + UserInfo.getUserId() + '-' +
String.valueOf(Datetime.now().getTime());
String tagPrefix = tag + '%';
List<Account> parents = new List<Account>{
new Account(Name = tag + '-Busy'),
new Account(Name = tag + '-Empty')
};
insert parents;
insert new List<Contact>{
new Contact(LastName = tag + '-Beta', AccountId = parents[0].Id),
new Contact(LastName = tag + '-Alpha', AccountId = parents[0].Id)
};Requirements
- Child count should be computed from the list
- Child subquery should be present
Accounts loaded:should be2Busy Account contacts:should be2Empty Account contacts:should be0Contacts sorted:should betrue