Courseiva

SF-PD2 Process Automation, Logic, and Integration Practice Question

Exhibit

{
  "error": "System.LimitException",
  "message": "Too many SOQL queries: 101"
}

Refer to the exhibit. An Apex trigger is failing during a mass update of records. The developer identifies that the SOQL query is inside a loop. Which pattern must be applied to fix this error while maintaining the required functionality?

⚠ Common exam trap

Candidates often try to solve the loop query problem by simply moving the query, but they fail to use a Map to retrieve the data efficiently, resulting in poor performance.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

✓

Collect all IDs in a Set and execute a single SOQL query outside the loop.

The 'Too many SOQL queries: 101' error is the most common indicator of a 'SOQL query in a loop' anti-pattern. To fix this, the developer must move the query outside the loop by collecting the necessary IDs into a Set or List first. Then, perform a single SOQL query that fetches all required records at once, storing them in a Map for efficient, constant-time retrieval during the trigger execution.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✗

    Increase the SOQL query limit by using a @future method to perform the query.

    Why it's wrong here

    Governor limits are fixed and cannot be increased. Moving queries to a @future method only shifts the query execution to another transaction, which might hit the same limit if the logic is not bulkified. The only correct approach is to bulkify the SOQL query to process data in sets.

  • ✓

    Collect all IDs in a Set and execute a single SOQL query outside the loop.

    Why this is correct

    Bulkifying the SOQL query by using a Set to gather IDs and executing the query once outside the loop ensures the code remains well within the 100-query governor limit. This approach is highly performant and the industry-standard way to write scalable Apex triggers that handle bulk data operations.

  • ✗

    Use the Database.queryAll() method to bypass standard governor limits.

    Why it's wrong here

    Database.queryAll() is used to query records including those in the recycle bin; it does not bypass or increase governor limits. All Apex code must adhere to the same governor limits, regardless of which query method is used, to ensure the multi-tenant platform remains stable for all users.

  • ✗

    Wrap the loop in a try-catch block to ignore the error and proceed with the remaining records.

    Why it's wrong here

    Ignoring a governor limit exception is not possible because the error is fatal and rolls back the entire transaction. A try-catch block will not prevent the transaction from failing. The root cause—the inefficient query inside the loop—must be corrected to ensure the code executes successfully for all records.

About these practice questions

One of 226 original SF-PD2 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written and reviewed by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

Last reviewed September 2026 · checked against the official Salesforce exam blueprint

This SF-PD2 practice question is part of Courseiva's free Salesforce certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the SF-PD2 exam.