nerdexam
Salesforce

PDI · Question #63

Consider the following code snippet: Given the multi-tenant architecture of the Salesforce platform, what Is a best practice a developer should Implement and ensure successful execution of the method?

The correct answer is D. Avoid performing queries inside for loops. Given Salesforce's multi-tenant architecture and governor limits, a developer's best practice is to avoid performing SOQL queries inside for loops to prevent exceeding query limits.

Submitted by rania.sa· Apr 18, 2026Logic and Process Automation

Question

Consider the following code snippet:

Given the multi-tenant architecture of the Salesforce platform, what Is a best practice a developer should Implement and ensure successful execution of the method?

Exhibit

PDI question #63 exhibit

Options

  • AAvoid executing queries without a limit clause.
  • BAvoid returning an empty List of records.
  • CAvoid using variables as query filters.
  • DAvoid performing queries inside for loops.

How the community answered

(20 responses)
  • B
    5% (1)
  • D
    95% (19)

Why each option

Given Salesforce's multi-tenant architecture and governor limits, a developer's best practice is to avoid performing SOQL queries inside `for` loops to prevent exceeding query limits.

AAvoid executing queries without a limit clause.

While using `LIMIT` clauses is often a good practice to restrict result sets, the primary issue leading to governor limit exceptions is the *number* of queries, not necessarily the lack of a limit on a single query.

BAvoid returning an empty List of records.

Returning an empty list of records is a perfectly valid and often expected outcome for queries that yield no results; it does not pose a problem for governor limits or execution.

CAvoid using variables as query filters.

Using variables as query filters is the standard and necessary way to make dynamic SOQL queries based on input or logic; this is not an anti-pattern or a cause of governor limit issues.

DAvoid performing queries inside for loops.Correct

Performing SOQL queries inside `for` loops is a common anti-pattern that can quickly exhaust the governor limit for the number of SOQL queries per transaction (100 for synchronous Apex). In a multi-tenant architecture, inefficient code like this can impact platform stability and lead to runtime exceptions.

Concept tested: Apex governor limits and best practices (SOQL in loops)

Source: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_gov_limits.htm

Topics

#Apex Best Practices#Governor Limits#SOQL#Bulkification

Community Discussion

No community discussion yet for this question.

Full PDI Practice