Lightning demos for Apex Cursors (Database.Cursor and pagination cursors) with LWC: infinite scroll, reporting drill-down, and adaptive async chunking. Blog posts: infinite scroll and pagination cursors. Also see associated Londons Calling presentation here and Apex Hours presentation here.
| Tab | What it shows |
|---|---|
| Infinite Loading | Database.Cursor + lightning-datatable infinite scroll (5,000 Accounts) |
| Reporting Drill Down | Pagination cursor + Chart.js brush/zoom on UnitPriceObservation__c |
| Adaptive Async | Cursor over Orders, callout-budgeted queueable chunks, AdaptiveAsyncChunk__e platform events |
Shared: ApexCursorDemo app and permission set.
- Salesforce CLI (
sf) installed and authenticated - A Dev Hub org configured
- Basic knowledge of Lightning Web Components and Apex
# Create a fresh scratch org
sf org create scratch --definition-file config/project-scratch-def.json --alias apex-cursor-demo --set-default --duration-days 7# Deploy all metadata to the scratch org
sf project deploy start# Run the Apex script to create dummy Account records
sf apex run --file apex/CreateDummyAccounts.apex# Assign the permission set
sf org assign permset --name ApexCursorDemo# Generate ~8 years of daily RAM/CPU unit prices (CSV)
node scripts/generate-price-observations.mjs
# Upsert into UnitPriceObservation__c
sf data upsert bulk \
-f data/unit-price-observations.csv \
-s UnitPriceObservation__c \
-i External_Id__c \
-o apex-cursor-demo \
-w 10# Infinite Loading tab
sf org open --path /lightning/n/InfiniteLoading
# Reporting drill-down tab (weekly chart + cursor detail)
sf org open --path /lightning/n/ReportingDrillingDown
# Adaptive Async tab (cursor + queueable + platform events)
sf org open --path /lightning/n/AdaptiveAsync# Generate CSV, delete existing ADAPT-ORD-* orders, then bulk upsert accounts and orders
node scripts/generate-adaptive-orders.mjs --load- Open the Demo: The command above will take you directly to the Infinite Loading tab
- View the Data Table: The component will automatically load the first batch of records
- Test Infinite Scrolling: Scroll to the bottom of the table to load more records
- Monitor Debug Info: Check the debug section at the bottom for real-time information
- Choose RAM or CPU and wait for the monthly chart (mid-month values via pagination cursor
fetchPage, no aggregate SOQL) - Drag across the chart to select a date range (snaps to days; drag handles to resize)
- Daily rows for that range load below via pagination cursor
fetchPagefrom session cache - Click Refresh to rebuild the session cursor and chart after data changes
- Open Adaptive Async in the Apex Cursor Demo app (1500 demo orders after Step 7; rerunnable without reset)
- Click Start run — each queueable scans the next cursor window and packs orders until
Limits.getLimitCallouts()predicted HTTP callouts would be exceeded - Progress bar updates as
AdaptiveAsyncChunk__eplatform events arrive - Bar chart — bar color reflects callout pressure (green / amber / red); chunk size varies with order mix
- Datatable lists each chunk (sequence, planned vs actual orders, predicted callouts, job id)