function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Saravana RavikumarSaravana Ravikumar 

what parameters does start method of batch class takes ?

prakash SFprakash SF
parameter for start() method in a Bacth class is Database.BatchableContext
VinayVinay (Salesforce Developers) 
Hi Saravana,

In Salesforce, the start method of a batch class takes in the following parameters:
  • BatchableContext: This is an object that provides context information for the batch job, such as the batch job ID, job name, and job scope.
  • Database.QueryLocator: This is an object that defines the scope of records to be processed by the batch job. It typically represents a query that returns a set of records to be processed.
  • (Optional) String: This is a string parameter that allows you to pass additional information to the start method, such as a filter criteria or a parameter for a custom logic.
Here's an example of how the start method might look like with these parameters.
 
global Database.QueryLocator start(Database.BatchableContext context) {
    // Define query to retrieve records to be processed
    return Database.getQueryLocator([SELECT Id, Name FROM Account]);
}
global void execute(Database.BatchableContext context, List<Account> scope) {
    // Process records in the current batch
}
global void finish(Database.BatchableContext context) {
    // Handle any post-processing logic
}

Please mark as Best Answer if above information was helpful.

Thanks,
Prateek Prasoon 25Prateek Prasoon 25
Text
      
    
    
    
      The start method of a batch class in Salesforce Apex takes a single parameter of type BatchableContext. This parameter provides information about the execution context of the batch job, such as the batch job ID, the scope size, and the query locator.
The method signature for the start method looks like this:
global Database.QueryLocator start(Database.BatchableContext context)
The return type of the start method is a Database.QueryLocator object, which represents a cursor over a set of records that the batch job will process. The query locator can be used to retrieve a set of records from the database that meet a certain criteria, such as all accounts that were created in the last week.
The start method is the first method that is called when a batch job is executed. It is responsible for initializing the batch job and returning a query locator that identifies the set of records to be processed by the batch job.

If you find my answer helpful, please mark it as the best answer. Thanks!
Arun Kumar 1141Arun Kumar 1141
Hi @Saravana,

START  METHOD :


At the start of a batch Apex job, call the start method to collect the records or objects to pass to the interface method execute. It will return either a Database.QueryLocator object or an iterable that has the objects or records passed to the job.

The start method of a batch class in Salesforce Apex takes a single parameter, which is an instance of the BatchableContext class. The BatchableContext class provides information about the execution context of the batch job. The start method signature is as follows:
 
public Database.QueryLocator start(Database.BatchableContext context)

Hope this is helpful.

Thank you.