[SalesForce] how to execute batch apex

global class DailyLeadProcessor implements
    Database.Batchable<sobject> {
        global Database.QueryLocator start(Database.BatchableContext bc)
        {
            string query = 'select name,leadsource from lead';
            return Database.getQueryLocator(query); 
        }
        global void execute(Database.BatchableContext BC, list<lead> scope)
        {
            for(lead l:scope)
            {
                l.LeadSource = 'Dreamforce';
            }
            update scope;
        }
        global void finish(Database.BatchableContext BC)
        {

        } 
}

Best Answer

To run batch Apex, go to User Menu --> Developer Console.

In the Apex Code section,

DailyLeadProcessor  M = new DailyLeadProcessor();
Database.executeBatch(M);

where DailyLeadProcessor is a Batch Apex Class

Related Topic