Thursday, September 30, 2021

Queueable Apex

 First Batch:

global class BatchCalledThroughQueueable implements Database.Batchable<sObject>, Database.Stateful, Database.AllowsCallouts {

    global Database.QueryLocator start(Database.BatchableContext bc) {

        return Database.getQueryLocator(query);

    }

    global void execute(Database.BatchableContext bc, List<Lead> records){

    }

    global void finish(Database.BatchableContext bc){

    }

}

Second Queueable Class:

public class ExecuteBatchQueueableJob implements Queueable {

    public void execute(QueueableContext context) {

        try{

            BatchCalledThroughQueueable b = new BatchCalledThroughQueueable();

            Database.executeBatch(b, 200);

        }catch(Exception e){

            System.debug('@@@ Error Message : '+e.getMessage());

        }

    }

}

Third Batch:

global class BatchUpdate implements Database.Batchable<sObject>, Database.StatefulDatabase.AllowsCallouts {

        global Database.QueryLocator start(Database.BatchableContext bc) {

            Note: Calling Queueable job for calling the next batchfor chaining.

                System.enqueueJob(new ExecuteBatchQueueableJob());

            return Database.getQueryLocator(query);

        }

    global void execute(Database.BatchableContext bc, List<Contact> records){

    }

    global void finish(Database.BatchableContext bc){

    }

}

No comments:

Post a Comment

CSS Styling

Styling: 1. Inline Styling: < div style = "font-size: 2rem;font-weight: 400;" > Good Evening </ div > 2. Usi...