I want to update a field in lead everyday with current date and the number of leads are around 40k. So can any one suggest any batch class CODE or anything?
global class LeadUpdateBatch implements Database.Batchable<sObject> {
global Database.QueryLocator start(Database.BatchableContext BC){
String queryString = 'SELECT Id, Field__c FROM Lead'; //Assuming Field__c is the Date field you need to update
return Database.getQueryLocator(queryString);
}
global void execute(Database.BatchableContext BC, List<Lead> scope){
List<Lead> leadsToUpdate = new List<Lead>();
for(Lead leadObj : scope){
leadObj.Field__c = Date.Toda();
leadsToUpdate.add(leadObj);
}
if(!leadsToUpdate.isEmpty()){
update leadsToUpdate;
}
}
global void finish(Database.BatchableContext BC){}
}
Create a scheduler class as below:
global class scheduledBatchable implements Schedulable {
global void execute(SchedulableContext sc) {
LeadUpdateBatch b = new LeadUpdateBatch();
database.executebatch(b);
}
}
You can schedule this class using Configuration : Setup -> Apex Class -> Schedule Apex (Daily, any time yu want) Using Cron expression
You can refer below code:
Create a scheduler class as below:
You can schedule this class using
Configuration : Setup -> Apex Class -> Schedule Apex (Daily, any time yu want)
Using Cron expression