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

Given a list of Opportunity records named opportunityList, which code snippet is best for querying all Contacts of the Opportunity’s Account?
A . List <Contact> contactList = new List <Contact>();
for(Opportunity o : opportunityList){
Account a = [SELECT Id, (SELECT Id FROM Contacts) FROM Account WHERE Id =
:o.AccountId]
contactList.addAll(a.Contacts);
)
B . List <Contact> contactList = new List <Contact>();
Set <Id> accountIds = new Set <Id> ();
for (Opportunity o : opportunityList){
contactIds.add(o.ContactId);
}
for(Contact c : [SELECT Id FROM Contact WHERE Id IN :contactIds]){
contactList.add(c);
}
C . List <Contact> contactList = new List <Contact>();
Set <Id> accountIds = new Set <Id> ();
for(Opportunity o : opportunityList){
accountIds.add(o.AccountId);
}
for(Account a : [SELECT Id, (SELECT Id FROM Contacts) FROM Account WHERE Id IN
:accountIds]){
07B13F58239056B81577933EB624485B
contactList.addAll(a.Contacts);
}

D . List <Contact> contactList = new List <Contact>();
for ( Contact c : [SELECT Id FROM Contact WHERE AccountId IN
:opportunityList.AccountId] ){
contactList.add(c);
}

Answer: C

Latest PDII Dumps Valid Version with 280 Q&As

Latest And Valid Q&A | 90 Days Free Update | Once Fail, Full Refund

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>