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.
// Get a query locator Database.QueryLocator q = Database.getQueryLocator( [SELECT Name FROM Account LIMIT 5]); // Get an iterator Database.QueryLocatorIterator it = q.iterator(); // Iterate over the records while (it.hasNext()) { Account a = (Account)it.next(); System.debug(a); }
The following are methods for QueryLocatorIterator. All are instance methods.
public Boolean hasNext()
Type: Boolean
public sObject next()
Type: sObject
Account a = (Account)myIterator.next();
Account a = (Account)myIterator.next();