Given a list of Opportunity records named opportunityList, which code snippet is best for querying all Contacts of the Opportunity's Account?

QuestionsCategory: Certified Platform Developer IIGiven a list of Opportunity records named opportunityList, which code snippet is best for querying all Contacts of the Opportunity's Account?
Admin Staff asked 4 months ago
Given a list of Opportunity records named opportunityList, which code snippet is best for querying all Contacts of the Opportunity's Account?

A. List  contactList = new List  contactList = new List  accountIds = new Set  (); for (Opportunity o : opportunityList){ contactIds.add(o.ContactId); } for(Contact c : [SELECT Id FROM Contact WHERE Id IN :contactIds]){ contactList.add(c); }

C. List  contactList = new List  accountIds = new Set  (); for(Opportunity o : opportunityList){ accountIds.add(o.AccountId); } for(Account a : [SELECT Id, (SELECT Id FROM Contacts) FROM Account WHERE Id IN :accountIds]){ contactList.addAll(a.Contacts); }

D. List  contactList = new List Suggested Answer: C

Community Answer: C



This question is in Certified Platform Developer II Exam
For getting Salesforce Certified Platform Developer II











Disclaimers:
The website is not related to, affiliated with, endorsed or authorized by Salesforce. 
Trademarks, certification & product names are used for reference only and belong to Salesforce.
The website does not contain actual questions and answers from Salesforce's Certification Exams.

Next Post

Recommended

Welcome Back!

Login to your account below

Create New Account!

Fill the forms below to register

Retrieve your password

Please enter your username or email address to reset your password.