PDI · Question #37
PDI Question #37: Real Exam Question with Answer & Explanation
Sign in or unlock PDI to reveal the answer and full explanation for question #37. The question stem and answer options stay visible for context.
Question
A developer must modify the following code snippet to prevent the number of SOQL queries issued from exceeding the platform governor limit. public class without sharing OpportunityService( public static List<OpportunityLineItem> getOpportunityProducts(Set<Id> opportunityIds){ List<OpportunitylineItem> oppLineItems = new List<OpportunityLineItem>(); for(Id thisOppId: opportunityIds){ oppLineItems.addAll([Select Id FROM OpportunityLineItems WHERE OpportunityId = :thisOppId)]; } return oppLineItems; } } The above method might be called during a trigger execution via a Lightning component. Which technique should be implemented to avoid reaching the governor limit?
Options
- AUse the System.Limits.getQueries() method to ensure the number of queries is less than 100.
- BUse the System.Limits.getlimitQueries() method to ensure the number of queries is less than 100.
- CRefector the code above to perform the SOQL query only if the Set of opportunityIds contains
- DRefactor the code above to perform only one SOQL query, filtering by the Set of opportunityIds.
Unlock PDI to see the answer
You've previewed enough free PDI questions. Unlock PDI for full answers, explanations, the timed quiz mode, progress tracking, and the master PDF. Question stem and options stay visible so you can still see what's on the exam.