nerdexam
Salesforce

CRT-450 · Question #37

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…

The correct answer is B. Use the System.Limits.getlimitQueries() method to ensure the number of queries is less than 100. See the full explanation below for the reasoning.

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.

How the community answered

(42 responses)
  • A
    10% (4)
  • B
    71% (30)
  • C
    5% (2)
  • D
    14% (6)

Community Discussion

No community discussion yet for this question.

Full CRT-450 Practice