Monday, 3 February 2014

Batch Apex in salesforce

/* you need to create a class and to schedule that class write one more class
*/

Class Name:- batchAccountUpdate



global class batchAccountUpdate implements Database.Batchable <sObject>
{
    global Database.QueryLocator start(Database.BatchableContext BC)
    {
        String query = 'SELECT Id,Name FROM Account';
        return Database.getQueryLocator(query);
    }
  
    global void execute(Database.BatchableContext BC, List<Account> scope)
    {
         for(Account a : scope)
         {
             a.Name = a.Name + 'L';
             update a;
         }
    }  
    global void finish(Database.BatchableContext BC)
    {
    }
}

// to schedule class: - scheduleExpireNotify

global class scheduleExpireNotify implements Schedulable
{
    global void execute(SchedulableContext sc)
    {
        batchAccountUpdate en = new batchAccountUpdate();
        Database.executeBatch(en);
    }
}