Can i make callouts from my batch class if they do not use @future in the way below. Is it required to use BATCH_SIZE of 1 ?

public class AccountBatch implements Database.Batchable<sObject>, Schedulable, Database.AllowsCallouts {

        // Batch size should be 1
        public static final Integer BATCH_SIZE = 1;

        public Database.QueryLocator start(Database.BatchableContext BC) {
            Set<String> nameSet;
            return Database.getQueryLocator([
                SELECT Id, Name FROM Account WHERE Name IN :nameSet]);

        public void execute(Database.BatchableContext BC, List<Account> scope) {
            for (Account o: scope) {
                // code to make callout which does not have @future annotation

        public void finish(Database.BatchableContext BC) {}

        public void execute(SchedulableContext sc) {
                AccountBatch job = new AccountBatch();
                Database.executeBatch(job, BATCH_SIZE);
  • Yes,the batch class have all accounts which are in scope.. Jul 11 '17 at 14:43
  • set nameSet will have around 1800 values.
    – Walker
    Jul 11 '17 at 14:48

nameSet is null, so every account in the database will be processed. That said, you don't need a where clause if that is your intent.

Also, as a matter of performance, consider increasing the batch size to 100. It'll run approximately 100 times faster that way.

You also don't need to break the loop, since that has no practical effect on a loop over just one element, but will break your code if you later change the batch size.

100 is the recommended limit because of the callout governor limit.

  • set nameSet will have around 1800 values. Will the break; in for loop allow processing of all the accounts.
    – Walker
    Jul 11 '17 at 14:49
  • @Walker if batch size is one, yes, but not if you make the batch size larger. I would recommend not breaking the loop.
    – sfdcfox
    Jul 11 '17 at 14:52

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.