Thursday 6 August 2015

Schedule Apex

global class Scheduleclass implements schedulable{
    //String cronExp = '0 5 * * * ?';
    //Scheduleclass s = new Scheduleclass();
    //String jobID = system.schedule('Scheduleclass JOB', cronExp, s);
    global void execute(schedulableContext sc){      
 
        Batchclass b = new Batchclass();
        DataBase.executeBatch(b, 100);
        system.debug('b----' +b);
    }
}


Execution:-
------------
system.schedule('Scheduleclass JOB', '0 8 * * * ?', new Scheduleclass());

* This Schedule job will execute every one hour by default.(Suppose today at 06h:08Mins it's executed next schedule will be 07h:08mins... like this it will be schedule)


Wednesday 5 August 2015

Batch class

Global class Batchclass implements Database.Batchable<Account>, Database.Stateful{
    Integer i ;
    public List<Account> listofunits = new List<Account>();
 
    global Iterable<Account> start(Database.BatchableContext bc){
     
        listofunits = [ SELECT Id, Name FROM Account ];
        i=10;
        return listofunits;
    }
    global void execute(Database.BatchableContext bc, List<Account> scope){

       // List<Account> a = [Select Id From Account where Id =: ];
        for(Account acc : scope ){
            if(acc.Name == 'Reddy'){
                acc.Type = 'Customer - Channel';
            }
            i = i+1;
            system.debug('i.......' +i);
        }
     //   update scope;
        system.debug('acc - '+Scope);
        system.debug('Scope - ' +scope.size());
    }
    global void finish(Database.BatchableContext bc){
   //     system.debug('a..........' +a);
    }
}