Salesforce Certified Platform Developer II — Question 184
A company has a custom object, Request_c, that has a checkbox field, Completed_c, and a Lookup to Opportunity, Opportunity_c.
Which SOQL query will get a unique list of all of the Opportunity records that have a Completed Request?
Answer options
- A. SELECT Opportunity_c FROM Request_c WHERE Id IN (SELECT Id FROM Request_c Where Completed_c = true)
- B. SELECT Opportunity_c FROM Request_c WHERE Completed_c = true
- C. SELECT Id FROM Opportunity WHERE Id IN (SELECT Id FROM Request_c WHERE Completed = true)
- D. SELECT Id From Opportunity WHERE Id IN (SELECT Opportunity_c FROM Request_c WHERE Completed_c = true)
Correct answer: D
Explanation
Option D is correct because it retrieves the unique Opportunity Ids linked to Request_c where Completed_c is true. Option A is incorrect because it selects from Request_c instead of Opportunity, and Option B fails to ensure uniqueness of Opportunity records. Option C is also incorrect as it attempts to select from Opportunity based on the Request_c's Completed status without properly referencing the Opportunity_c field.