Batch Apex Syntax

Syntax:

global class class_Name Implements Database.Batchable <sObject> {
    global Database.queryLocator start(Database.BatchableContext bc) {
        String SOQL = 'SELECT Id FROM sObject';
        return Database.getQueryLocator(SOQL);
    }

    global void execute(Database.BatchableContext bc, List<sObject> scope) {
    }

    global void finish(Database.BatchableContext bc) {
    }
}

To execute:

Class_Name obj = new Class_Name();
Database.executeBatch(obj);

To schedule:

global class Scheduleclass_Name Implements Schedulable {
    global void execute(SchedulableContext sc) {
        Class_Name obj = new Class_Name();
        Database.executeBatch(obj);
    }
}

Cheers!!!

No comments:

Post a Comment