grzmol/vibe-force/sf-async-apex-patterns
Claude Code and agent skill by grzmol/vibe-force
- community
- ext:[{"type":"hook","description":"Pre/post lifecycle hooks"}]
Checking that the SKILL.md file is still in the repository.
Selects and implements the right Salesforce asynchronous execution model - Queueable Apex with Finalizers, Batch Apex, Apex Cursors, Schedulable Apex with CRON expressions, future methods, Platform Events, and Change Data Capture - and covers chaining limits, scope sizing, Database.Stateful, transaction boundaries, idempotency, duplicate delivery, and job monitoring or abort through AsyncApexJob and CronTrigger. Use this skill when work involves System.enqueueJob, System.attachFinalizer, Database.executeBatch, Database.getQueryLocator, Database.getCursor, System.schedule, System.scheduleBatch, System.abortJob, EventBus.publish, EventBus.RetryableException, setResumeCheckpoint, @future, BatchApexErrorEvent, ChangeEventHeader, a *__e platform event, a *ChangeEvent trigger, an AsyncApexJob or CronTrigger query, or when a long-running or high-volume process must move off the synchronous transaction.
Install
npx vskill@latest install grzmol/vibe-force/sf-async-apex-patternsSemi-extensibleMentions customization, but needs skill-specific knowledge. Read the extensible skills standard
SKILL.md
The same SKILL.md was published earlier as grzmol/vibe-force/sf-async-apex-patterns.
Asynchronous Apex Patterns
When to use
Use this skill when a Salesforce requirement cannot finish inside one synchronous transaction: callouts from a trigger, data volumes above 50,000 query rows, scheduled maintenance, long-running integration work, or cross-system event propagation. It owns the choice of async mechanism and the correctness concerns that choice creates (retries, duplicate delivery, state, transaction boundaries).
Related skills: sf-apex-development (trigger/handler structure, with sharing, user mode), sf-apex-testing (all async test mechanics), sf-governor-limits (full per-transaction limit tables), sf-soql-sosl-optimization (query locator and cursor query tuning), sf-integration-patterns (callout design, Named Credentials), sf-debugging-logs (debug logs for async contexts), sf-deployment-strategies (deploying classes with pending scheduled jobs).
Decision table
Pick the leftmost row whose constraints all hold.
| Mechanism | Max data reach | State | Callouts | Chaining | Transaction boundary | Choose when | |
|---|---|---|---|---|---|---|---|
Queueable | 50,000 query rows per execution (50M rows with Database.Cursor) | full object state; non-primitive members serialized | yes, with Database.AllowsCallouts | 1 child per job; stack depth unlimited in prod, 5 in Developer/Trial | one transaction per execute | default async choice; complex arguments; ordered steps; needs a job id | |
Queueable + Database.Cursor | 50M rows per cursor | full | yes | self re-enqueue per chunk | one per chunk | large volume without consuming Batch Apex slots | |
Database.Batchable | 50M rows via QueryLocator | only with Database.Stateful (instance members) | yes, with Database.AllowsCallouts, 100 callouts per method | Database.executeBatch from finish | one transaction per execute chunk | record-set processing with per-chunk limit resets and per-chunk error isolation | |
Schedulable | delegates | persists between runs unless transient | no synchronous callouts | schedules batch/queueable | synchronous limits apply | clock-driven work; CRON schedule | |
@future | 50,000 query rows | none; primitives and primitive collections only | yes, with @future(callout=true) | cannot call another future | one transaction | legacy only, or mixed-DML isolation. Salesforce recommends Queueable instead | |
Platform event (*__e) | subscriber batch up to 2,000 messages | none | no callouts from event triggers | publish from subscriber | publisher and subscriber are separate transactions | decoupled fan-out, retry semantics, external subscribers | |
Change Data Capture (*ChangeEvent) | 1 event may carry many recordIds | none | no | publish from trigger | change event trigger runs after the DB transaction completes | replicate record deltas without writing publish code | |
| Record-triggered flow async path | flow limits | flow variables | via invocable action | subflow | runs immediately after the triggering save completes | declarative async; see skill sf-flow-automation |
Hard numbers behind the table: Queueable allows up to 50 System.enqueueJob calls per synchronous transaction but only 1 from an asynchronous transaction; Developer and Trial orgs cap the chained stack depth at 5 (the parent plus four children); Database.QueryLocator may return up to 50 million records and the job fails immediately above that; executeBatch scope caps at 2,000 with a QueryLocator and has no upper bound with an Iterable; five batch jobs may be queued or active at once with up to 100 more held in the Apex flex queue; 100 scheduled Apex jobs may exist at one time; every async execution counts against the shared org limit of 250,000 async executions per 24 hours or user licences x 200, whichever is greater.
Core patterns
1. Queueable with callouts, delay, and duplicate suppression
Enqueue with a minimum delay (0-10 minutes, ignored in tests) and a duplicate signature so a second identical job is rejected with DuplicateMessageException:
A queueable signature is cleared when the job is dequeued, so duplicates of an already running job are still possible. Treat the signature as contention control, not as an exactly-once guarantee.
2. Finalizer as the failure boundary
The finalizer runs in its own Apex and database transaction, so DML buffered in the finalizer's state survives a queueable that blew its limits. Only one finalizer per queueable job; a finalizer may enqueue exactly one async job; the retry chain caps at 5 consecutive failures and resets on success.
3. Batch Apex with stateful aggregation and chaining
Only instance members survive between chunks under Database.Stateful; statics are reset. Use a scope size that is a factor of 2,000 (100, 200, 400...). Avoid relationship subqueries in the QueryLocator: a QueryLocator without subqueries uses the fast chunked implementation, while an Iterable or a subquery forces the slower non-chunking path. FOR UPDATE in the start query does not apply to Batch Apex; requery with FOR UPDATE inside execute when you need row locks.
4. Apex Cursor plus chained Queueable for high volume
A cursor spans up to 50 million rows, allows at most 100 Cursor.fetch() calls per transaction, and each fetch counts against the SOQL query and query-row limits. Cursors consume no Batch Apex slots and never queue behind the flex queue. System.TransientCursorException is retryable; System.FatalCursorException is not.
5. Schedulable with CRON and one-shot batch scheduling
Job names must be unique or System.AsyncException: The Apex job named "..." is already scheduled for execution is thrown. Apex cannot be scheduled more often than hourly. Scheduled Apex runs under synchronous governor limits and cannot make synchronous web-service callouts - delegate callouts to Queueable or Batch with Database.AllowsCallouts.
6. Platform events with an idempotent subscriber
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/sf-async-apex-patterns/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Extension points
hookPre/post lifecycle hooks
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/grzmol/vibe-force/sf-async-apex-patterns)