Process Data 360 Data Model Objects with Apex Cursors (Beta)

Use Apex cursors with Data 360 data model objects (DMOs) to process large SOQL query result sets in manageable chunks. Create a cursor with Database.getCursor(), retrieve records with Cursor.fetch(), and get the result set size with Cursor.getNumRecords(). Monitor Data 360 cursor rows, cursor instances, and Data 360 Flex Credit limits as you process DMO records.

Where: This feature is available in API version 68.0 and later. This feature is available in Lightning Experience and Salesforce Classic in Enterprise, Performance, Unlimited, and Developer editions.

Important
Important Apex Cursors for Data 360 Data Model Objects is a pilot or beta service that is subject to the Beta Services Terms at Agreements - Salesforce.com or a written Unified Pilot Agreement if executed by Customer, and applicable terms in the Product Terms Directory. Use of this pilot or beta service is at the Customer's sole discretion.

How: In Apex, call Database.getCursor() with a SOQL query against a DMO. Use Cursor.fetch() to retrieve records in chunks and Cursor.getNumRecords() to get the number of records in the result set. Apex cursors for Data 360 DMOs expire 24 hours after creation, and System.InvalidQueryLocatorException is thrown if it expires before processing completes.

For example, this code creates a cursor for the Individual__dlm DMO.

public with sharing class DataChunkProcessor implements Queueable {
    private Database.Cursor cursor;
    private Integer position;

    public DataChunkProcessor() {
        // Initialize cursor with DC SOQL
        this.cursor = Database.getCursor('SELECT Name__c, Email__c FROM Individual__dlm');
        this.position = 0;
    }

    public void execute(QueueableContext context) {
        // Fetch a chunk of 200 records without hitting SOQL query row limits or heap limits
        List<Individual__dlm> records = cursor.fetch(position, 200);

        // Process records
        for (Individual__dlm rec : records) {
            // Business logic
        }

        this.position += records.size();

        // Chain the next job if more records are left
        if (this.position < cursor.getNumRecords()) {
            System.enqueueJob(this);
        }
    }
}

Use the Limits class to get Data 360 cursor instance and Data 360 cursor row limits. SOQL queries against DMOs consume Data Services credits from your Data 360 subscription. See Data Cloud License Billing and Limits.