57 lines
2.0 KiB
OpenEdge ABL
57 lines
2.0 KiB
OpenEdge ABL
global class threeObjectUpdate implements Schedulable, Database.Batchable<sObject>
|
|
|
|
{
|
|
List<Id> failedUpdates;
|
|
global Database.QueryLocator start(Database.BatchableContext BC)
|
|
{
|
|
String query1 = 'SELECT Id,Description, NumberOfEmployees,(SELECT LastName FROM Contacts) FROM Account';
|
|
|
|
return Database.getQueryLocator(query1);
|
|
|
|
|
|
}
|
|
|
|
global void execute(Database.BatchableContext BC, List<Account> scope)
|
|
{
|
|
for(Account a : scope)
|
|
{
|
|
a.Description = 'New Description from batch 2';
|
|
a.NumberOfEmployees =200;
|
|
|
|
for(Contact con:a.Contacts){
|
|
con.LastName= 'Last batch Name';
|
|
}
|
|
}
|
|
List<Database.SaveResult> results = Database.update(scope, false);
|
|
for (Database.SaveResult result : results) {
|
|
if (!result.isSuccess()) {
|
|
failedUpdates.add(result.getId());
|
|
}
|
|
}
|
|
}
|
|
global void finish(Database.BatchableContext BC){
|
|
if (!failedUpdates.isEmpty()) {
|
|
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
|
|
mail.setToAddresses(new String[] {'himanshu.s@hicglobalsolutions.com'});
|
|
mail.setSubject('Batch Apex Failure');
|
|
String messageBody = 'The following records failed to update: ';
|
|
for (Id failedId : failedUpdates) {
|
|
messageBody += failedId + ', ';
|
|
|
|
}
|
|
mail.setPlainTextBody(messageBody);
|
|
|
|
Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
|
|
}
|
|
}
|
|
global void execute(SchedulableContext SC) {
|
|
threeObjectUpdate batchJob = new threeObjectUpdate();
|
|
Database.executeBatch(batchJob);
|
|
}
|
|
|
|
public static void scheduleJob() {
|
|
threeObjectUpdate batchJob = new threeObjectUpdate();
|
|
String cronExpression = '0 0 0 ? * MON *'; // Every Monday at midnight
|
|
System.schedule('Update Account Batch', cronExpression, batchJob);
|
|
}
|
|
} |