sf-async-apex-patterns

Implements Salesforce asynchronous Apex patterns including Queueable, Batch, Schedulable, Platform Events, and CDC.

2|Updated Sep 12, 2026
One-click install
npx skills add https://github.com/grzmol/vibe-force --skill sf-async-apex-patterns-grzmol
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sf-async-apex-patterns
Source: https://github.com/grzmol/vibe-force/tree/main/skills/sf-async-apex-patterns
Command: npx skills add https://github.com/grzmol/vibe-force --skill sf-async-apex-patterns-grzmol

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Long-running or high-volume Salesforce work cannot finish inside one synchronous transaction, and choosing the wrong async mechanism causes governor-limit failures, duplicate processing, and silent job losses. This Skill selects the correct asynchronous execution model and implements it with correct retry, state, and transaction-boundary handling. ## Core Features & Use Cases - Mechanism selection: A decision table maps constraints (data volume, callouts, chaining, state) to Queueable, Batch Apex, Apex Cursors, Schedulable, future methods, Platform Events, or Change Data Capture. - Production-ready patterns: Copyable Apex implementations covering Queueable with Finalizers and duplicate signatures, stateful Batch with chaining, cursor-based high-volume processing, CRON scheduling, idempotent platform event subscribers, and CDC triggers. - Operations and monitoring: Runbooks for querying AsyncApexJob, CronTrigger, and EventBusSubscriber, aborting runaway jobs, and verifying async health after deployment. - Use Case: When a trigger needs to call an external ERP for thousands of accounts, use this Skill to implement a Queueable with Database.AllowsCallouts, attach a Finalizer for failure logging, and monitor the job through AsyncApexJob queries. ## Quick Start Ask the assistant to implement a Queueable Apex job with a Finalizer that syncs accounts to an external ERP and handles retries and duplicate suppression.

Frequently Asked Questions about sf-async-apex-patterns

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

FAQPage Schema
How do I choose between Queueable and Batch Apex in Salesforce?

Use Queueable as the default async choice for complex arguments, ordered steps, and callouts; use Batch Apex for record-set processing above 50,000 rows with per-chunk limit resets and error isolation. Batch supports up to 50 million records via QueryLocator, while Queueable chains one child per job.

How do I handle failures in a Queueable Apex job?

Attach a Transaction Finalizer with System.attachFinalizer inside the queueable execute method. The finalizer runs in its own transaction, receives the failure exception via FinalizerContext, and can re-enqueue the failed job up to five consecutive times.

Can Batch Apex make callouts to external APIs?

Yes, Batch Apex supports callouts when the class implements Database.AllowsCallouts, with a limit of 100 callouts per start, execute, or finish method. Because chunks can re-run after service maintenance, any callout inside execute must be idempotent.

Why did my platform event trigger stop receiving events?

The subscriber likely exceeded the retry cap after throwing EventBus.RetryableException nine times, moving it to the Error state and disconnecting it. Query EventBusSubscriber for Status != 'Running', fix and save the trigger to resume; events published during the outage are lost.

What are the limits for chaining Queueable jobs?

A queueable can enqueue only one child job, and Developer or Trial orgs cap chained stack depth at 5. Bound chains with AsyncOptions.MaximumQueueableStackDepth and check AsyncInfo.getCurrentQueueableStackDepth before re-enqueuing to avoid burning the daily async limit.

Why does deploying a Schedulable Apex class fail?

Deployment fails with 'This schedulable class has jobs pending or in progress' when an active CronTrigger references the class. Abort the scheduled job with System.abortJob, deploy the class, then reschedule it.