The ScheduleExtractionDynamicJob
What is the ScheduleExtractionDynamicJob?
The ScheduleExtractionDynamicJob is required to extract schedules from the big objects and store them in the sObject and viceversa.
When does the ScheduleExtractionDynamicJob run?
Whenever the amortization schedule reaches a schedule ((n-3) schedule) after which only 3 schedules of the future are left in sObject, the ScheduleExtractionDynamicJob runs and stores the required number of schedules in the sObject and big object as per the parameters defined in org parameters during enabling this optimzation.
If there are less than 3 schedules left in the future in the sObject, then the system determines the next schedule (n-2) and runs the job.
n, n-3, n-2 and so on
n-3 is the best case scenario when the ScheduleExtractionDynamicJob is required to run.
However, in the scenarios when there are less than 3 schedules left in the future in the sObject, then the system determines the next immediate schedule (n-2) and runs the job when it reaches that schedule, and so on.
Here, (n-3) schedule is the schedule after which only 3 schedules of the future are left in the sObject, where n is the number of future schedules stored in the sObject. For example, if 12 schedules of the future are stored in the sObject, then n-3 schedule = 12 - 3 = 9th schedule.
n is the number of schedules falling in the number of months specified in the Store Schedules After Fixed Period Of parameter. These n schedules are stored in the sObject.
For example, if Store Schedules After Fixed Period Of = 6 months, and payment frequency is weekly, then 6x4 = 24 schedules are stored in sObject and so n = 24. Therefore, n-3 = 21. This means that when the system reaches the 21st schedule, after which 3 more schedules are stored in the sObject, it runs the ScheduleExtractionDynamicJob to determine the schedules falling in the next 6 months from the 21st schedule, and accordingly moves the required number of schedules from the big object to the sObject. This process keeps repeating.
This ensures that at any given point in the amortization schedules, at the most 3 future schedules must be displayed and stored in the sObject.
For the first disbursal, the system directly allocates the amortization schedules to sObject or to big objects as per the parameters defined in Org parameters during enabling this optimzation. It is not done by the ScheduleExtractionDynamicJob.
In addition, when a loan is rescheduled, the system marks the old schedules as archived and directly adds them into the big object, and generates new schedules and adds them to either sObject or big object as per the parameters defined in Org parameters during enabling this optimzation.
The adding to the sObject and big object during disbursal and rescheduling is not done by the ScheduleExtractionDynamicJob.
What does the job do when only three (or less) schedules of the future are remaining in the sObject?
Every time the ScheduleExtractionDynamicJob runs, after it stores the new number of future schedules in the sObject. From these new number of future schedules, the system determines that schedule, after which only three schedules of the future are left in the sObject. It then considers the date of this schedule as the next schedule extraction date. This schedule is the (n-3) schedule where n is the number of future schedules stored in the sObject.
And so, when a loan reaches the (n-3) schedule, the ScheduleExtractionDynamicJob runs to determine the new future n schedules and extracts the required schedules from the big object and stores them in the sObject. Similarly, it runs to determine the past schedules and extracts the unwanted past schedules from the sObject and stores it in the big object. This process keeps repeating at every (n-3) schedule.
(The same process takes place if there are less than 3 schedules left in the future. In such a case, the job runs on the immediate next schedule.)
To understand this better, refer to the example in Example.