Courseiva
Performance →hardMultiple Choice

SF-PD2 Performance Practice Question

An Apex trigger is failing due to a 'System.LimitException: Too many DML statements: 151'. What is the optimal refactoring approach?

⚠ Common exam trap

Candidates often mistakenly attempt to fix the error by increasing the batch size or splitting the code into multiple triggers, rather than addressing the core lack of bulkification.

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 code to collect records in a List and perform one DML.

The error clearly indicates the failure to bulkify DML. The solution is to collect all records needing updates into a single list and perform one DML statement after the loop. This reduces 150+ individual operations to one, keeping the code within governor limits and significantly improving performance by reducing the number of round-trips to the database during the transaction processing cycle.

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 DML statement limit in the Apex class.

    Why it's wrong here

    Governor limits are fixed and cannot be changed by the developer. The platform enforces these limits to maintain system stability and prevent resource-intensive code from affecting other tenants. The only way to resolve this error is to optimize the code to perform fewer DML operations per transaction.

  • ✓

    Refactor the code to collect records in a List and perform one DML.

    Why this is correct

    Bulkification is the core design pattern for Salesforce development. Moving DML outside the loop ensures that only one DML statement is used regardless of the number of records, which completely eliminates the 'Too many DML statements' error and makes the code scalable and highly performant.

  • ✗

    Move the logic to a @future method to allow more DML.

    Why it's wrong here

    While @future methods execute in a separate transaction, they still have their own DML limits. This approach simply shifts the problem rather than solving it. Furthermore, it adds unnecessary complexity and latency by introducing asynchronous processing for logic that should be handled synchronously in the trigger.

  • ✗

    Use the Database.update() method with allOrNone set to false.

    Why it's wrong here

    Using Database.update() does not change the number of DML statements consumed. If the code is still calling update inside a loop, it will hit the same limit regardless of the allOrNone setting. Bulkification is the only way to avoid the limit exception in this scenario.

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.