Courseiva

SF-PD2 Advanced Developer Fundamentals Practice Question

Exhibit

{
  "apex_class": "PolicyService",
  "method": "processRecords",
  "error": "System.LimitException: Too many SOQL queries: 101"
}

Refer to the exhibit. The developer observes the error above. What is the most efficient architectural change to prevent this limit from being hit?

⚠ Common exam trap

Candidates often try to solve this by using @future methods, which is a poor architectural choice that adds unnecessary complexity and latency compared to simply bulkifying the code.

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

✓

Refactor the logic to collect IDs and execute a single SOQL query before the loop.

The 'Too many SOQL queries: 101' error indicates that queries are being executed inside a loop. By moving the SOQL queries outside of the loop and utilizing Map-based lookups, the developer can satisfy the requirements for data access while adhering to governor limits. This transition from iterative query execution to bulkified access is the hallmark of scalable Salesforce development.

Answer analysis

Option-by-option breakdown

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

  • ✗

    Wrap the SOQL queries in a try-catch block to handle the exception gracefully.

    Why it's wrong here

    Catching a LimitException is generally discouraged as it does not resolve the underlying issue of exceeding governor limits. The transaction will still fail, and the user will not receive the expected result. Proper bulkification is the only way to ensure the code executes successfully within the defined platform constraints.

  • ✓

    Refactor the logic to collect IDs and execute a single SOQL query before the loop.

    Why this is correct

    Executing a single query outside the loop allows the developer to store results in a Map. Inside the loop, the developer can then perform O(1) lookups. This pattern is the standard for bulkifying Apex code and ensures the total number of queries remains well below the limit of 100.

  • ✗

    Increase the Apex heap size in the class definition.

    Why it's wrong here

    There is no configuration to increase governor limits for Apex heap or SOQL queries. These are fixed platform limits enforced to maintain multi-tenant health. Increasing heap size would not solve the SOQL limit issue, as the problem is related to the number of queries executed, not memory consumption.

  • ✗

    Use an @future method to process each record individually.

    Why it's wrong here

    Calling an @future method inside a loop will trigger a 'Too many future calls' limit exception. Even if it were allowed, it creates unnecessary asynchronous overhead and does not solve the underlying inefficiency of the original design. Bulkifying the SOQL query is the correct architectural solution for this scenario.

About these practice questions

Courseiva writes every SF-PD2 question from scratch — 226 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. 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.