Salesforce Certified Platform Developer II — Question 197

A developer has a requirement to query three fields (Id, Name, Type) from an Account and First and Last names for all Contacts associated with the Account.

Which option is the preferred optimized method to achieve this for the Account named ‘Ozone Electronics’?

Answer options

Correct answer: A

Explanation

Option A is the preferred method as it executes two separate queries efficiently, first fetching the Account and then the related Contacts using the Account ID. Option B is less optimal because it attempts to retrieve the Contacts in a subquery, which can be less efficient than handling them in separate queries. Option C unnecessarily retrieves additional fields and uses a loop, making it less efficient. Option D is incorrect as it uses a JOIN which is not a supported operation in SOQL for this context.