Newer Version Available
QueryLocatorIterator Class
Represents an iterator over a query locator record set.
Namespace
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.
1swfobject.registerObject("clippy.codeblock-0", "9");
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17// Get a query locator
18Database.QueryLocator q = Database.getQueryLocator(
19 [SELECT Name FROM Account LIMIT 5]);
20// Get an iterator
21Database.QueryLocatorIterator it = q.iterator();
22
23// Iterate over the records
24while (it.hasNext())
25{
26 Account a = (Account)it.next();
27 System.debug(a);
28}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();