async-apex
Use when selecting, designing, or reviewing Queueable, Batch, Future, or Schedulable Apex for callouts, large data processing, retries, or background work. Triggers: 'queueable vs batch', 'future method', 'flex queue', 'async job failed', 'schedule apex'. NOT for Platform Events or a deep-only Batch Apex implementation guide.
Best use case
async-apex is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Use when selecting, designing, or reviewing Queueable, Batch, Future, or Schedulable Apex for callouts, large data processing, retries, or background work. Triggers: 'queueable vs batch', 'future method', 'flex queue', 'async job failed', 'schedule apex'. NOT for Platform Events or a deep-only Batch Apex implementation guide.
Teams using async-apex should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/async-apex/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How async-apex Compares
| Feature / Agent | async-apex | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Use when selecting, designing, or reviewing Queueable, Batch, Future, or Schedulable Apex for callouts, large data processing, retries, or background work. Triggers: 'queueable vs batch', 'future method', 'flex queue', 'async job failed', 'schedule apex'. NOT for Platform Events or a deep-only Batch Apex implementation guide.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
Use this skill when synchronous Apex is the wrong execution model or when an existing async design is brittle. The core job is to choose the smallest async mechanism that fits the workload, preserves observability, and does not create hidden limit or chaining failures. ## Before Starting - How many records or payloads can this process handle at peak, not just in the happy-path demo? - Does the work need outbound callouts, a scheduled start time, or multiple transactions with fresh limits? - Do you need monitoring, retry visibility, or a job ID that operations can inspect later? ## Core Concepts ### Queueable Is The Default Modern Async Tool For most application-level async work, start with `Queueable`. It supports complex member variables, gives you an `AsyncApexJob` record to monitor, and is usually the right replacement for legacy `@future` code. It is especially strong for "finish DML, then make a callout" patterns when combined with `Database.AllowsCallouts`. ### Batch Exists For Scale And Fresh Limits Per Scope Use Batch Apex when the workload can exceed normal transaction limits or when you need to process very large data volumes in chunks. Each `execute()` scope gets fresh governor limits. That makes Batch the right tool for record sets that can grow beyond what one Queueable should reasonably hold. It is not the default choice for every background task because it adds more framework overhead and operational complexity. ### Future Is Legacy And Narrow `@future` still exists, but it is intentionally constrained. Parameters must be primitive types or collections of primitives, and it offers weaker monitoring and composition than Queueable. Keep it for simple legacy code paths only when there is no need for chaining, non-primitive state, or richer operational visibility. ### Schedulable Starts Work; It Should Rarely Do All The Work `Schedulable` is the timer, not usually the worker. A scheduler should dispatch a Queueable or Batch job instead of performing large business logic inline. This keeps recurring jobs maintainable and avoids turning cron logic into a second processing framework. ## Common Patterns ### Post-Commit Queueable For Callouts **When to use:** A trigger or synchronous service must perform a callout after data is saved. **How it works:** Collect record IDs in the original transaction, enqueue one Queueable, re-query inside the job, and implement `Database.AllowsCallouts` when HTTP work is required. **Why not the alternative:** Doing the callout in-trigger or using `@future` by default makes monitoring, retry design, and composition worse. ### Batch For Large, Query-Driven Workloads **When to use:** The record count may exceed one transaction or you need controlled chunking with `start`, `execute`, and `finish`. **How it works:** Use `Database.getQueryLocator()` in `start()`, keep `execute()` idempotent, and summarize outcomes in `finish()`. ### Scheduler As Dispatcher **When to use:** Work must begin on a cron schedule. **How it works:** The `Schedulable.execute` method launches a Batch or Queueable and exits quickly, leaving the heavy lifting to the right async mechanism. ## Decision Guidance | Situation | Recommended Approach | Reason | |---|---|---| | Trigger must perform a callout after DML for tens or hundreds of records | Queueable + `Database.AllowsCallouts` | Clean post-commit boundary with monitoring and chaining support | | Nightly cleanup or reprocessing may touch thousands to millions of rows | Batch Apex | Fresh limits per scope and native large-volume processing | | Small legacy fire-and-forget method only needs primitive inputs | `@future` only if there is no reason to modernize | Supported, but weaker than Queueable | | Work must start on a schedule | Schedulable launching Queueable or Batch | Separates timer concerns from worker concerns | ## Recommended Workflow Step-by-step instructions for an AI agent or practitioner activating this skill: 1. Gather context — confirm the org edition, relevant objects, and current configuration state 2. Review official sources — check the references in this skill's well-architected.md before making changes 3. Implement or advise — apply the patterns from Core Concepts and Common Patterns sections above 4. Validate — run the skill's checker script and verify against the Review Checklist below 5. Document — record any deviations from standard patterns and update the template if needed --- ## Review Checklist - [ ] The chosen async mechanism matches data volume and operational needs, not team habit. - [ ] Queueable jobs are not enqueued inside loops. - [ ] Queueables that make callouts implement `Database.AllowsCallouts`. - [ ] Batch jobs use an idempotent `execute()` path and summarize failures in `finish()`. - [ ] Legacy `@future` methods are justified instead of being the default. - [ ] Schedulers dispatch work rather than containing heavy processing inline. ## Salesforce-Specific Gotchas 1. **`@future` parameters are constrained** — pass IDs or primitives, then re-query inside the async method. 2. **A running Queueable can only chain one child Queueable job** — fan-out designs need a different approach. 3. **Tests do not run async work until `Test.stopTest()`** — asserting before `stopTest()` produces false negatives. 4. **Batch `execute()` gets fresh limits, but that does not excuse non-idempotent logic** — retries or re-runs can still duplicate side effects if the code is not designed carefully. ## Output Artifacts | Artifact | Description | |---|---| | Async decision matrix | Recommended use of Queueable, Batch, Future, or Schedulable for the current workload | | Async review findings | Findings on callouts, chaining, monitoring, and bulk safety | | Migration plan | Practical move from `@future` or overloaded schedulers to modern async patterns | ## Related Skills - `apex/callouts-and-http-integrations` — use when the async question is really about outbound HTTP design, Named Credentials, or callout error handling. - `apex/governor-limits` — use when the problem is transaction budgeting or loop-driven limit failures, not just async mechanism choice. - `apex/test-class-standards` — use alongside this skill to validate Queueable, Batch, and scheduler behavior correctly in tests.
Related Skills
apex-managed-sharing-patterns
Grant row-level access programmatically via __Share records when declarative sharing rules cannot express the policy. NOT for OWD, role hierarchy, or criteria-based sharing rule design.
omnistudio-asynchronous-data-operations
Use Integration Procedures queues, DataRaptor Chain, and Remote Actions with async patterns for long-running OmniStudio flows. NOT for simple DataRaptor reads.
lwc-imperative-apex
Call Apex methods imperatively from LWC — on button click, lifecycle hooks, or conditional logic. Covers import syntax, cacheable vs non-cacheable, async/await patterns, error handling, loading states, and Promise.all. NOT for wire service (use wire-service-patterns) and NOT for testing Apex mocks (use lwc-testing).
dataweave-for-apex
Use when transforming structured data inside Apex — CSV → JSON, XML → SObject list, JSON → flattened CSV, or schema-mapping a third-party payload to a Salesforce model — and the existing options (`JSON.deserialize`, `Dom.Document`, hand-written loops) are getting unwieldy. Triggers: 'apex transform csv json xml without external library', 'system.dataweave script', 'salesforce native dataweave apex execute', 'transform xml to sobject apex no mulesoft', 'json reshape salesforce apex script'. NOT for MuleSoft Anypoint DataWeave running off-platform (use mulesoft-anypoint-architecture), NOT for Apex JSON serialization basics (use apex-json-serialization), NOT for Bulk API CSV ingest (use bulk-api-2-patterns).
callout-limits-and-async-patterns
Use when designing or troubleshooting Apex callouts that approach governor limits: choosing between synchronous callouts, @future, Queueable, Continuation, or async chaining strategies. NOT for HTTP request construction or Named Credential setup (use named-credentials-setup).
flow-invocable-from-apex
Author @InvocableMethod Apex classes that Flow can call as Actions. Design the input / output variable contract, bulk semantics (one list in, one list out), null handling, and error surfacing. Also covers the inverse direction: calling a flow from Apex via Flow.Interview. NOT for general Apex authoring (use apex-service-selector-domain). NOT for REST-exposed Apex (use apex-rest-resource-patterns).
flow-apex-defined-types
Design and use Apex-Defined Types as Flow variables for structured non-sObject data (HTTP callout payloads, External Service responses, complex configuration). Trigger keywords: apex-defined type, flow variable, @AuraEnabled class, flow http callout response. Does NOT cover building HTTP Callout Actions themselves, External Services schema, or raw Apex invocable methods.
scheduled-apex-failure-detection-and-monitoring
Use when nightly batch / scheduled Apex jobs are failing without anyone noticing — covers why uncaught exceptions in `execute()` go to the debug log instead of email, how to query `AsyncApexJob` for `Status`, `NumberOfErrors`, and `ExtendedStatus`, when to implement `Database.RaisesPlatformEvents` so the platform publishes `BatchApexErrorEvent` on uncaught failures, how to subscribe to that event with an Apex trigger and notify operators, and how to layer a custom watcher schedule on top so silent-failure modes (job that never started, scheduled class deleted, queue stuck on `Queued`) still surface. Triggers: 'nightly batch failed at 2am with no notification', 'how do we know if a scheduled apex job is failing', 'BatchApexErrorEvent vs custom retry logic', 'Setup Apex Jobs only shows last 7 days, where else can I look', 'job is stuck in queued status nobody noticed for a week'. NOT for general Apex exception handling patterns (use apex/apex-exception-handling-and-logging), NOT for Batch Apex authoring or chunking strategy (use apex/batch-apex-design), NOT for Setup → Apex Jobs UI walkthrough as an admin task (use admin/batch-job-scheduling-and-monitoring), NOT for retry logic itself (use apex/scheduled-apex-retry-patterns once authored).
platform-events-apex
Use when publishing or subscribing to Salesforce Platform Events from Apex, comparing Platform Events with Change Data Capture, or designing event-triggered error handling and monitoring. Triggers: 'EventBus.publish', 'platform event trigger', 'CDC vs Platform Events', 'replay ID', 'high-volume event'. NOT for Flow-only publish/subscribe automation.
health-cloud-apex-extensions
Use this skill when extending Health Cloud via Apex: implementing HealthCloudGA managed-package interfaces, automating care plan lifecycle hooks, processing referrals using Industries Common Components invocable actions, or enforcing HIPAA-compliant logging governance for clinical Apex code. Trigger keywords: CarePlanProcessorCallback, HealthCloudGA namespace, ReferralRequest, ReferralResponse, care plan invocable actions, clinical Apex extension, Health Cloud Apex API. NOT for standard Apex triggers or generic Apex development unrelated to Health Cloud managed-package extension points.
fsl-apex-extensions
Use when writing Apex that calls Field Service Lightning scheduling APIs — AppointmentBookingService, ScheduleService, GradeSlotsService, or OAAS — to book, schedule, grade, or optimize service appointments programmatically. Trigger keywords: FSL Apex namespace, GetSlots, schedule service appointment via code, appointment booking API, FSL optimization API. NOT for standard Apex patterns unrelated to FSL, admin-level scheduling policy configuration, or declarative FSL scheduling.
fsc-apex-extensions
Use this skill when extending Financial Services Cloud (FSC) behavior through Apex: customizing financial rollup recalculation, disabling built-in FSC triggers to write custom trigger logic, implementing Compliant Data Sharing (CDS) participant/role integrations, or building custom FSC action handlers. NOT for standard Apex unrelated to the FSC managed package, standard Salesforce sharing rules, or configuring FSC rollups through the Admin UI — use the admin/financial-account-setup skill for declarative rollup setup.