ads

Wednesday 27 July 2016

Schedule a Batch Class






Batch  Class :-



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
global class batchContactupdate implements Database.Batchable<sObject> {

global Database.QueryLocator start(Database.BatchableContext BC)
     {
    string Query='Select Name, Type from Contact';
     return Database.getQueryLocator(Query);
     }
       global void execute(Database.BatchableContext BC, List<Contact> scope)
       {
        for (Contact a : Scope)
        {
            a.Description='----This Description is updated by Batch Class------';
        }
       update Scope;
       
       }
     
      global void finish(Database.BatchableContext BC) 
    {
    }
 }

Scheduled Class :-



1
2
3
4
5
6
7
8
9
global class scheduledBatchable implements Schedulable {


   global void execute(SchedulableContext sc)
    {
      batchContactupdate b = new batchContactupdate(); 
      database.executebatch(b);
    }
}



Cron Expression :-


1
2
3
scheduledBatchable sc = new scheduledBatchable();
String sch = '0 5 * * * ?';
String jobID = system.schedule('Update Contact Job', sch, sc);


Scheduled Jobs :-




Apex Jobs :-







No comments:

Post a Comment