Newer Version Available
QueryLocator Class
Represents the record set returned by Database.getQueryLocator and used
with Batch Apex.
Namespace
QueryLocator Methods
The following are methods for QueryLocator. All are instance methods.
getQuery()
Returns the query used to instantiate the Database.QueryLocator object. This
is useful when testing the start method.
Signature
public String getQuery()
Return Value
Type: String
Usage
You cannot use the FOR UPDATE keywords with a getQueryLocator query to lock a set of records. The start method automatically locks the set of records in the batch.
Example
1System.assertEquals(QLReturnedFromStart.
2getQuery(),
3Database.getQueryLocator([SELECT Id
4 FROM Account]).getQuery() );iterator()
Returns a new instance of a query locator iterator.
Signature
public Database.QueryLocatorIterator iterator()
Return Value
Usage
For an example, see QueryLocatorIterator Class.