Schedule Nightly Reconciliation (Batch + Scheduled)
By the end of this lesson, you'll be able to:
- Combine Schedulable and Batchable Apex into one nightly reconciliation job
- Explain why reconciliation runs nightly rather than in real time
- Reuse Module 39's exact scheduled-batch-chaining pattern
Prerequisites: "Integrate with an External Ledger"
The Schedulable wrapper
global class NightlyReconciliationJob implements Schedulable {
global void execute(SchedulableContext sc) {
Database.executeBatch(new RecalculateBalancesBatch(), 50);
}
}
String cronExpr = '0 0 2 * * ?'; // 2:00 AM daily
System.schedule('Nightly Balance Reconciliation', cronExpr, new NightlyReconciliationJob());
This is Module 39's exact scheduled-batch shape, reused directly — a Schedulable class whose only job is to kick off Lesson 3's RecalculateBalancesBatch on a nightly cron schedule.
Why nightly, not real time
The trigger from Lesson 2 already keeps balances correct in real time for normal operations; this nightly job exists purely as Lesson 3's safety net. Running the full recalculation across every account constantly would be wasteful — a low-traffic overnight window is exactly when Module 41's "release management" thinking about low-risk timing applies just as well to batch jobs as it does to deployments.
What "reconciliation" means here
Reconciliation is the general accounting practice of confirming two independently-derived numbers agree — here, the stored Balance__c against a freshly recalculated sum of Transaction__c history. A mismatch found and silently corrected by this nightly job is exactly the kind of drift Lesson 3 described, caught automatically rather than discovered by a customer noticing an incorrect balance.
Exercise
As a comment, write the cron expression for running NightlyReconciliationJob at 3:30 AM daily instead of 2:00 AM.
Show hint
Cron format is: seconds minutes hours day-of-month month day-of-week.
Schedule Nightly Reconciliation (Batch + Scheduled) Quiz
My Notes
Log in to keep private notes on this lesson.
Questions about this lesson
No questions yet — be the first to ask.
Log in to ask a question about this lesson.
Summary
A Schedulable class runs Lesson 3's recalculation batch every night — the identical scheduled-plus-batch combination from Module 39's stuck-order reconciliation job, applied here to financial balance integrity.