Courseiva
Performance →mediumMultiple Choice

SF-PD2 Performance Practice Question

A developer has a requirement to update 5,000 records in a single transaction. The operation frequently hits the 'Too many DML statements' limit. What is the most efficient way to refactor the code?

⚠ Common exam trap

Candidates often choose solutions involving asynchronous processing for simple bulk updates, or mistakenly think using a Map instead of a List will solve DML statement limit violations inside a loop.

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 one DML statement after the loop.

Governor limits enforce boundaries on DML statements within a single transaction to ensure platform stability. Performing DML inside a loop is a violation of best practices because each statement counts against the limit. Refactoring the code to collect records in a list and performing a single DML operation outside the loop reduces the number of statements from 5,000 to one, ensuring the code remains scalable and efficient for large datasets.

Answer analysis

Option-by-option breakdown

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

  • ✗

    Use the Database.upsert method inside the loop.

    Why it's wrong here

    Calling any DML method inside a loop still increments the counter for total DML statements in the transaction. Even with bulk DML methods, the loop ensures that each iteration invokes a new database call, which will eventually hit the limit of 150 DML statements per execution context.

  • ✗

    Add the 'future' annotation to the update method.

    Why it's wrong here

    Adding @future to the method only pushes the execution to another thread; it does not solve the DML limit within the calling transaction if the calling transaction itself is trying to perform many updates. Furthermore, @future methods have their own limits on the number of parameters and DML operations.

  • ✓

    Collect records in a list and perform one DML statement after the loop.

    Why this is correct

    Performing a single DML statement on a list of records is the standard pattern for bulkifying Apex code. This approach uses only one of the 150 allowed DML statements, allowing the transaction to handle larger record volumes efficiently while significantly reducing the load on the database engine.

  • ✗

    Increase the DML governor limit using the Apex setup menu.

    Why it's wrong here

    Governor limits are fixed by Salesforce to protect the multi-tenant environment and cannot be modified by developers. Any attempt to bypass these limits via configuration is not supported, and developers must instead optimize their code to operate within the defined boundaries of the platform's execution context.

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.