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?
Recent Comments (The most recent comments are at the top.)
B is already a bad practice. DML or query inside a loop is a bad practice.
Correct answer is C. We can refractor the code so that
[Select Id FROM OpportunityLineItems WHERE OpportunityId = :opportunityIds] where query returns all OpportunityLineItems related to OpportunityId.
B is the correct answer