Simple Batch Apex example that extend Schedulable Interface In the Batch Apex in Salesforce
Apex Code:
global class batchAccountUpdate implements Database.Batchable<sObject>,schedulable {
global Database.QueryLocator start(Database.BatchableContext BC) {
String query = 'SELECT Id,Name FROM Account';
return Database.getQueryLocator(query);
}
global void execute(SchedulableContext sc) {
for(Account a : scope)
{
a.Name = a.Name + 'Updated';
}
update scope;
}
global void finish(Database.BatchableContext BC) {
}
}
global class batchAccountUpdate implements Database.Batchable<sObject>,schedulable {
global Database.QueryLocator start(Database.BatchableContext BC) {
String query = 'SELECT Id,Name FROM Account';
return Database.getQueryLocator(query);
}
global void execute(SchedulableContext sc) {
batchAccountUpdate b = new batchAccountUpdate(); database.executebatch(b); }global void execute(Database.BatchableContext BC, List<Account> scope) {
for(Account a : scope)
{
a.Name = a.Name + 'Updated';
}
update scope;
}
global void finish(Database.BatchableContext BC) {
}
}
Thanks Vishvendra..
ReplyDeleteThis concept is a good way to enhance the knowledge.thanks for sharing. please keep it up salesforce Online Training Hyderabad
ReplyDelete