Courseiva
Performance →mediumMultiple Select

SF-PD2 Performance Practice Question

A developer is optimizing a complex Apex transaction that processes a large number of records. The transaction currently performs multiple SOQL queries and DML operations inside loops. Which two strategies should be used to improve performance and avoid governor limit errors? (Choose two.)

⚠ Common exam trap

The trap here is focusing on error handling or asynchronous processing instead of the core bulkification techniques that directly reduce governor limit usage.

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 records in a list and perform a single DML operation after the loop instead of DML inside the loop.

The two key strategies are to move SOQL queries outside of loops and to consolidate DML operations. These practices, known as bulkification, minimize database round trips and governor limit consumption. They are essential for processing large data volumes efficiently in Apex. The other options either do not address the root cause or are not valid optimizations.

Answer analysis

Option-by-option breakdown

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

  • ✓

    Collect records in a list and perform a single DML operation after the loop instead of DML inside the loop.

    Why this is correct

    Performing DML inside a loop causes multiple database operations, quickly hitting the DML governor limit (150 statements) and degrading performance. Collecting records in a list and executing one DML operation after the loop is the recommended bulkification pattern. This reduces database round trips and improves transaction speed.

  • ✗

    Use @future annotation on the method to run the DML asynchronously and avoid limits.

    Why it's wrong here

    Using @future moves the operation to a separate transaction, but it does not solve the inefficiency within the current transaction. Future methods have their own limits and cannot be used when a synchronous response is needed. This is not a direct optimization for the current transaction's performance and does not address the loop-based DML.

  • ✗

    Increase the heap size by using the Limits.getHeapSize() method to monitor and adjust.

    Why it's wrong here

    The heap size limit is fixed (6 MB synchronous, 12 MB asynchronous) and cannot be increased. Limits.getHeapSize() is used for monitoring, not for increasing the limit. This does not improve performance or avoid governor limits related to SOQL and DML inside loops.

  • ✗

    Use Database.insert with the allOrNone parameter set to false to allow partial success and continue processing.

    Why it's wrong here

    While allOrNone=false allows partial DML success, it does not improve performance or reduce the number of DML operations. It is useful for error handling but does not address the inefficiency of performing DML inside loops. The developer should still consolidate DML operations to avoid hitting the DML statement limit (150).

  • ✓

    Move SOQL queries outside of loops and use a single query to retrieve all necessary records.

    Why this is correct

    Moving SOQL queries outside of loops is a fundamental best practice to avoid hitting the SOQL query limit (100) and to reduce database round trips. A single query can retrieve all required records, which can then be processed in memory. This approach is essential for bulk processing and is a key optimization for performance.

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.