Skip to content

Add AsyncResultCleanupBatch with per-track retention#43

Merged
Mateusz7410 merged 2 commits into
mainfrom
feature/async-0007
Jul 5, 2026
Merged

Add AsyncResultCleanupBatch with per-track retention#43
Mateusz7410 merged 2 commits into
mainfrom
feature/async-0007

Conversation

@Mateusz7410

Copy link
Copy Markdown
Collaborator

Summary

  • New AsyncResultCleanupBatch (global, packaged): deletes old AsyncResult__c records with separate retention per track. failedOlderThanDays(n) covers FAILED, othersOlderThanDays(n) covers the rest (COMPLETED + SKIPPED_*). Explicit config required, at least one track, days > 0. Dormant until scheduled via the lib itself: Async.batchable(new AsyncResultCleanupBatch().failedOlderThanDays(90).othersOlderThanDays(30)).asSchedulable()...
  • Cache QueueableJob.className in a transient property so the intentional DateTime-cast TypeException lands in debug logs once per job instead of on every access. Transient means the cached value never survives serialization, so a deserialized job always recomputes from its own runtime type (no cross-class contamination). Context: Receiving error "System.TypeException: Invalid conversion from runtime type CleanupFinalizer to Datetime" in logs #42.
  • Docs: new "AsyncResult Cleanup" and "Expected Exceptions in Debug Logs" explanation pages, sidebar entries, pointers from getting-started, batchable and queueable pages. Fixed 4 vitepress ::: containers that prettier's proseWrap had mangled (title swallowed the body text, literal ::: rendered on the page).
  • Packaging: cleanup class added to the public->global rewrite list in create-unlocked-package-version.sh.

Why

AsyncResult__c grows unbounded (#2). Failed results usually need longer retention for debugging than the rest, so two independent tracks. The #42 reporter was alarmed by the expected TypeException in logs, so it is now documented and logged far less often.

Closes #2

Test plan

  • bash scripts/agent/verify.sh full passed: 159/159, org coverage 99%, new class 100%
  • bash scripts/agent/verify.sh ns passed: 18/18 consumer scripts on the btcdev scratch
  • Package proof: beta built with the global rewrite, installed on a no-namespace scratch. 17/17 consumer scripts, packaged AsyncTest 159/159, plus a consumer script exercising btcdev.AsyncResultCleanupBatch. Beta and scratch deleted after.

Files

  • force-app/main/default/classes/cleanup/AsyncResultCleanupBatch.cls (+meta)
  • force-app/main/default/classes/queue/QueueableJob.cls
  • force-app/main/default/classes/AsyncTest.cls
  • scripts/create-unlocked-package-version.sh
  • website/explanations/asyncresult-cleanup.md
  • website/explanations/expected-exceptions-in-debug-logs.md
  • website/api/queueable.md
  • website/api/batchable.md
  • website/.vitepress/config.mts
  • website/getting-started.md

Dual retention for AsyncResult__c cleanup: failedOlderThanDays(...) for
FAILED results, othersOlderThanDays(...) for the rest. Explicit config
required, dormant until scheduled. Also cache QueueableJob.className
(transient) so the intentional TypeException logs once per job, document
that expected exception (issue #42), and fix the broken vitepress
containers in the queueable docs.

Closes #2
@vercel

vercel Bot commented Jul 5, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
async-lib Ready Ready Preview, Comment Jul 5, 2026 6:25pm

Request Review

@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown

🧪 Apex Test Results

✅ All Tests Passed

==========================================
     APEX TEST EXECUTION SUMMARY
==========================================

📊 Total Tests: 159
✅ Passed: 159
❌ Failed: 0
⏭️  Skipped: 0


🎉 All tests passed successfully!

📦 Download Full Test Results & Logs


📊 Stats: 159 total | ✅ 159 passed | ❌ 0 failed
🤖 Automated comment by Salesforce CI

Use 'delete as system scope' so the cleanup batch works regardless of the
running user's delete permission on AsyncResult__c. Drop the redundant
className cache comment.
@Mateusz7410
Mateusz7410 merged commit d16c4d6 into main Jul 5, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature idea: Support automatic cleanup of AsyncResult__c records

1 participant