OrgReady

Salesforce Skills & Readiness

Learning progress is unavailable. Reading and direct practice remain available; completion controls are disabled.

← Back to Salesforce Development

Lesson 6 of 6 · 5–10 minutes including the walkthrough and reflection

Error Handling & Production Patterns

A production operation needs an explicit failure contract. A successful method return must not conceal an incomplete business operation.

The concept

DML statements can throw exceptions. Database methods can support partial success, allowing inspection of individual results. Decide whether the operation needs all-or-nothing behavior or independent record outcomes. Catching an exception is not the same as reporting or recovering from it; callers need a meaningful result.

Worked example

Illustrative result contract:
For each requested item:
    record success or failure
    retain a safe diagnostic reference
Return an honest summary
Do not label the whole operation successful if required work failed

Imagine three independent requests with one invalid input. A partial-success contract can report two successes and one failure. For a single business operation that requires all three changes, that contract would be inappropriate. Choose the business boundary before choosing exception handling.

Common mistake

Swallowing an exception and returning success, or using partial success without inspecting failed record results.

Interview angle

Explain the required consistency, what the caller observes and how failures can be investigated. Avoid claiming that error handling is complete because a catch block exists.

Pause and apply

Write two versions of the same business request: one where each record is independent and one where all changes must succeed together. Describe the user-visible result for each failure. The linked validation exercise reinforces rejecting invalid changes; it does not cover every operational recovery pattern.

Official references

Reviewed 2026-09-13. Examples are illustrative; no code is executed here.

Apply it in practice

Business Validation with addError

Marking a lesson as read records learning activity, not mastery. Practice evidence continues to come from the challenge system.

Practice without marking read