error-handling

Standardize Salesforce Apex error handling with domain exceptions and Platform Event logging.

2|Updated Mar 18, 2026
One-click install
npx skills add https://github.com/bhanu91221/claude-sfdx-iq --skill error-handling-bhanu91221
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: error-handling
Source: https://github.com/bhanu91221/claude-sfdx-iq/tree/main/skills/error-handling
Command: npx skills add https://github.com/bhanu91221/claude-sfdx-iq --skill error-handling-bhanu91221

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Structured, reliable error handling in Apex to prevent silent failures by introducing domain-specific exceptions, centralized service-boundary try-catch, and consistent logging and messaging.

Core Features & Use Cases

  • Custom exception classes for domain-specific errors with rich context
  • Service-boundary try-catch to translate failures into user-friendly messages
  • Database.SaveResult handling and error aggregation for bulk operations
  • Platform Event logging to track critical errors without adding DML in-flight
  • Guidance for trigger validation using addError and robust error reporting

Quick Start

Define domain-specific exceptions and centralize try-catch at service boundaries to standardize error handling across your Apex codebase.

Frequently Asked Questions about error-handling

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I handle DML errors in Salesforce Apex without causing silent failures?

Handle DML errors in Apex by processing Database.SaveResult to aggregate failures and using Platform Event logging to capture critical errors. This approach standardizes error reporting across services and batch processes without swallowing exceptions or adding in-flight DML overhead.

What is the best way to structure Apex exception handling for bulk operations?

The best way to structure Apex exception handling for bulk operations is to implement service-boundary try-catch blocks and aggregate Database.SaveResult errors. This standardizes failures across triggers and batch processes while translating them into user-friendly messages.

Can I use Platform Events to log Apex exceptions without hitting DML limits?

Yes, you can use Platform Event logging to track critical Apex exceptions without adding DML in-flight. This method persists errors asynchronously, preventing silent failures and avoiding governor limits during bulk operations or integration point processing.

How do I create custom exception classes for domain-specific Apex errors?

Create custom exception classes for domain-specific Apex errors by extending the base Exception class and adding rich context. Centralize try-catch logic at service boundaries to translate these domain failures into consistent, user-friendly messages.

When should I use addError for trigger validation versus service-boundary try-catch in Apex?

Use addError for trigger validation to report row-level failures directly to the user, while service-boundary try-catch handles broader Apex exception aggregation. Combining both ensures robust error reporting without swallowing critical failures across the execution context.

Why do my Salesforce Apex batch jobs fail silently without logging errors?

Apex batch jobs fail silently when exceptions are caught and swallowed without logging. Implement centralized service-boundary try-catch with Platform Event logging to persist these failures, ensuring critical DML errors and validation issues are captured and reported reliably.