Salesforce Platform Developer I (legacy) — Question 22

An org has a single account named `˜NoContacts' that has no related contacts. Given the query:
List<Account> accounts = [Select ID, (Select ID, Name from Contacts) from Account where Name=`˜NoContacts'];
What is the result of running this Apex?

Answer options

Correct answer: B

Explanation

When the query is executed, it will return the account with no associated contacts, resulting in an empty collection for the contacts. Thus, accounts[0].contacts is an empty Apex collection, not null or invalid. Options A, C, and D are incorrect because they misinterpret the result of the query.