Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.

QueryLocatorIterator Class

Represents an iterator over a query locator record set.

Namespace

Database

Example

This sample shows how to obtain an iterator for a query locator, which contains five accounts. This sample calls hasNext and next to get each record in the collection.

1// Get a query locator
2Database.QueryLocator q = Database.getQueryLocator(
3    [SELECT Name FROM Account LIMIT 5]);
4// Get an iterator
5Database.QueryLocatorIterator it =  q.iterator();
6 
7// Iterate over the records
8while (it.hasNext())
9{
10    Account a = (Account)it.next();
11    System.debug(a);
12}

QueryLocatorIterator Methods

The following are methods for QueryLocatorIterator. All are instance methods.

hasNext()

Returns true if there are one or more records remaining in the collection; otherwise, returns false.

Signature

public Boolean hasNext()

Return Value

Type: Boolean

next()

Advances the iterator to the next sObject record and returns the sObject.

Signature

public sObject next()

Return Value

Type: sObject

Usage

Because the return value is the generic sObject type, you must cast it if using a more specific type. For example:
1Account a = (Account)myIterator.next();

Example

1Account a = (Account)myIterator.next();