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
Priyanka DumkaPriyanka Dumka 

How we can pass the parameter if we calling batch from another batch (from finish method)?

How we can pass the parameter if we calling batch from another batch (from finish method)?
SwethaSwetha (Salesforce Developers) 
HI Priyanka,
To pass parameters from a Salesforce batch class to another batch class, you can use the Database.executeBatch method with the appropriate constructor signature to pass the parameters.

See https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_database.htm#apex_System_Database_executeBatch

Example:

>> Consider below as 2nd batch class
public class SecondBatch implements Database.Batchable<SObject> {
    private String param1;
    private Integer param2;

    public SecondBatch(String param1, Integer param2) {
        this.param1 = param1;
        this.param2 = param2;
    }

    // Implement the execute, start, and finish methods
    // ...
}

>> In the first batch class, create an instance of the second batch class with the parameters you want to pass:
public class FirstBatch implements Database.Batchable<SObject> {
    // ...

    public void finish(Database.BatchableContext context) {
        // Pass parameters to the second batch class
        SecondBatch secondBatch = new SecondBatch('param1 value', 42);
        Database.executeBatch(secondBatch);
    }
}

See related: https://salesforce.stackexchange.com/questions/155940/passing-parameter-from-one-batch-apex-into-another-batch-apex

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_batch_interface.htm

If this information helps, please mark the answer as best. Thank you