Running a Batch Class from a Queueable Job

Question:
I am trying to call a batch process from a Queueable job, but I am getting the following error:
Method does not exist or incorrect signature: void DeliveryScheduleSync_batch() from the type DeliveryScheduleSync
Here is the code inside my Queueable class:
public void execute(QueueableContext context) {
Boolean isRunning = Utils.deliveryScheduleProcessing;
if(!isRunning && myContext.triggerType == 'Delivery_Schedule__c' && myContext.isAfter){
isRunning = true;
Database.executeBatch(DeliveryScheduleSync_batch());
}
}And here is the beginning of my batch class:
global class DeliveryScheduleSync_batch implements Database.Batchable<SObject> {
global void createQueryString() {
Id masterScheduleRTId = Utils.getRecordTypeId('Delivery_Schedule__c', 'Master Schedule');
Date yesterday = System.today().addDays(-1);
query = 'SELECT Id, RecordTypeId, AssetId__c, Contact__c ' +
'FROM Delivery_Schedule__c ' +
'WHERE LastModifiedDate > :' + yesterday +
'AND RecordTypeId == ' + masterScheduleRTId +
'OR Master_Schedule__c <> null';
}
global Database.Querylocator start(Database.BatchableContext bc) {
createQueryString();
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext bc, List<Delivery_Schedule__c> oDeliverySchedules){
// logic here
}
}Why am I seeing this error and how can I fix it?
Answer:
The issue is that you are calling the batch class like a method instead of creating an instance of it. In Apex, when you call a batch, you must pass an instance of the class that implements the Database.Batchable interface into Database.executeBatch().
Boost your career with CRS Info Solutions’ Salesforce online training, offering expert guidance and practical experience. Master the Salesforce ecosystem through comprehensive, hands-on learning.
So this line:
Database.executeBatch(DeliveryScheduleSync_batch());should be written as:
Database.executeBatch(new DeliveryScheduleSync_batch());This way, Salesforce instantiates your batch class and executes it as expected.
If you want to specify the batch size, you can also pass a second argument:
Database.executeBatch(new DeliveryScheduleSync_batch(), 200);This will process records in batches of 200.
Here’s the cleaned-up version:
global class DeliveryScheduleSync_batch implements Database.Batchable<SObject> {
private String query;
// Empty constructor (you can extend it to accept parameters if needed)
global DeliveryScheduleSync_batch() { }
// Helper method to build query
private void createQueryString() {
Id masterScheduleRTId = Utils.getRecordTypeId('Delivery_Schedule__c', 'Master Schedule');
Date yesterday = System.today().addDays(-1);
query = 'SELECT Id, RecordTypeId, AssetId__c, Contact__c ' +
'FROM Delivery_Schedule__c ' +
'WHERE LastModifiedDate > :yesterday ' +
'AND RecordTypeId = :masterScheduleRTId ' +
'OR Master_Schedule__c != null';
}
// Start method
global Database.QueryLocator start(Database.BatchableContext bc) {
createQueryString();
return Database.getQueryLocator(query);
}
// Execute method
global void execute(Database.BatchableContext bc, List<Delivery_Schedule__c> oDeliverySchedules) {
// Your batch logic goes here
}
// Finish method
global void finish(Database.BatchableContext bc) {
// Post-processing logic, if needed
}
}And your Queueable class should now call it like this:
public void execute(QueueableContext context) {
Boolean isRunning = Utils.deliveryScheduleProcessing;
if(!isRunning && myContext.triggerType == 'Delivery_Schedule__c' && myContext.isAfter){
isRunning = true;
Database.executeBatch(new DeliveryScheduleSync_batch(), 200);
}
}The batch class is properly declared with global class ... implements Database.Batchable<SObject>, and it includes an explicit constructor global DeliveryScheduleSync_batch() to allow instantiation when called from the Queueable. The SOQL query is stored in a class-level variable and constructed before the start() method executes, ensuring clean separation of logic.
Finally, the Queueable job correctly invokes the batch using Database.executeBatch(new DeliveryScheduleSync_batch(), 200), which creates a new instance and specifies the batch size for processing. This approach ensures proper execution of the batch process while maintaining flexibility and control over record processing.
Summing Up
The batch class is correctly structured with a global declaration, an explicit constructor, and a well-organized query built before execution. It integrates seamlessly with the Queueable job, which properly invokes it using Database.executeBatch(new DeliveryScheduleSync_batch(), 200). This ensures clean logic, proper instantiation, and efficient record processing.
Master Salesforce with Expert Training in Hyderabad
Kickstart your career with our comprehensive Salesforce training in Hyderabad. Whether you’re new to Salesforce or looking to enhance your skills, our program offers specialized tracks in Salesforce Administration, Development, and Artificial Intelligence. We equip you with the knowledge and hands-on experience necessary to excel in the tech industry.
Our training program includes interactive modules, real-world projects, and expert-led sessions to ensure you’re fully prepared for certification exams and interviews. Our experienced instructors provide personalized attention, making even complex concepts easy to understand.
Start your journey to success today! Enroll for the free demo and set yourself on the path to a rewarding future!!!

