Database.QueryLocator Class

The following table lists the method for the Database.QueryLocator class.

Name Return Type Description
getQuery String Returns the query used to instantiate the Database.QueryLocator object. This is useful when testing the start method. For example:
System.assertEquals(QLReturnedFromStart.
getQuery(),
Database.getQueryLocator([SELECT Id
   FROM Account]).getQuery() );

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.

iterator Database. QueryLocatorIterator Returns a new instance of a query locator iterator.
Warning
To iterate over a query locator, save the iterator instance that this method returns in a variable and then use this variable to iterate over the collection. Calling iterator every time you want to perform an iteration can result in incorrect behavior because each call returns a new iterator instance.

For an example, see Database.QueryLocatorIterator Class.

© Copyright 2000–2013 salesforce.com, inc. All rights reserved.
Various trademarks held by their respective owners.