I am writing a batch class on external object. Here I am using database.getQuerylocator in start method as the result will contain more thank 50k records.

Batch class code:

global class <batchclassname> implements Database.Batchable<sObject>, Database.Stateful, Database.AllowsCallouts {
    global String sQuery;
    global Database.QueryLocator start(Database.BatchableContext BC){
       sQuery = 'SELECT Id,....other field from <externalobject> ';
        return Database.getQueryLocator(sQuery);
    global void execute(Database.BatchableContext BC, List<sObject> scope) {
    global void finish(Database.BatchableContext BC){


Here in logs rows = -1

Can anyone help me if there is any issue with the code or I need to do any other configuration?

Note : In external data source Server Driven Pagination = true Request row count = true

Same code is working fine with Iterable. Since the records are more I can not use Iterable interface.

  • the below code is returning values in anonymous block: String sQuery = 'SELECT Id,....other field from <externalobject> limit 1'; system.debug('result'+Database.getQueryLocator(sQuery)); system.debug(Database.getQueryLocator(sQuery)); Apr 26 '19 at 16:19
  • 2
    Pretty sure query locators are only supported on the Salesforce Database.
    – Adrian Larson
    Apr 26 '19 at 16:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.