sf-apex-cursor

Paginate large SOQL result sets using Database.Cursor and PaginationCursor APIs.

13|2|Updated Mar 18, 2026
One-click install
npx skills add https://github.com/jiten-singh-shahi/salesforce-claude-code --skill sf-apex-cursor
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sf-apex-cursor
Source: https://github.com/jiten-singh-shahi/salesforce-claude-code/tree/main/.cursor/skills/sf-apex-cursor
Command: npx skills add https://github.com/jiten-singh-shahi/salesforce-claude-code --skill sf-apex-cursor

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Enables efficient pagination and processing of very large SOQL result sets without relying on OFFSET, avoiding heap bloat and OFFSET-driven performance degradation for large datasets.

Core Features & Use Cases

  • Server-side pagination at scale: use Database.Cursor to iterate up to 50,000,000 rows while keeping heap usage per-page only.
  • Async Queueable chaining: serialize cursor IDs and chain Queueable jobs to continue processing across transactions.
  • LWC and Flow integration: use PaginationCursor for @AuraEnabled endpoints to support infinite scroll and paged UI components.
  • Use Case: Replace OFFSET-based UI pagination or heavy Batch Apex jobs with cursor-based iteration to maintain performance beyond 2,000 rows.

Quick Start

Open a Database.Cursor for your SOQL, fetch pages of up to 2000 rows, and pass the cursor ID into chained Queueable jobs to process the full result set.

Frequently Asked Questions about sf-apex-cursor

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

FAQPage Schema
How do I paginate large SOQL result sets in Apex beyond the OFFSET limit?

To paginate large SOQL result sets beyond OFFSET limits, use Database.Cursor to iterate up to 50,000,000 rows. This fetches pages of up to 2000 rows, preventing heap bloat and avoiding OFFSET-driven performance degradation in Apex.

What is the best way to process millions of rows in Apex without hitting heap limits?

Processing millions of rows without hitting heap limits requires using Database.Cursor to fetch pages of up to 2000 rows. Chaining Queueable jobs and passing the cursor ID across transactions iterates up to 50,000,000 records while keeping heap usage strictly per-page.

Can I use cursor-based pagination to support infinite scroll in LWC?

Yes, you can support infinite scroll in LWC using the PaginationCursor API. Exposing @AuraEnabled endpoints delivers paged query results directly to LWC UI components, replacing OFFSET-based UI pagination for large datasets.

Does Database.Cursor work with Queueable Apex for asynchronous processing?

Database.Cursor works with Queueable Apex by serializing cursor IDs and chaining Queueable jobs. This transaction-aware async chaining continues processing across jobs, enabling full result set iteration up to 50,000,000 records without exceeding transaction limits.

How do I migrate from Batch Apex to cursor-based iteration for large data processing?

To migrate from Batch Apex to cursor-based iteration, open a Database.Cursor for your SOQL query, fetch pages of up to 2000 rows, and pass the cursor ID into chained Queueable jobs. This replaces heavy Batch Apex jobs while maintaining performance for large datasets.

What are the limitations of using Database.Cursor for SOQL pagination?

Limitations of Database.Cursor include requiring strict lifecycle management (open, fetch, close) and capping fetch page sizes at 2000 rows. You must also design transaction-aware async chaining to process the maximum of 50,000,000 records effectively.