I have a custom object record with a start date, an end date, and a amount field. I want to be able to take the difference between the two dates in number of months, divide the amount by the difference and then create related records based on the difference count. To make a basic schedule.
I think I have to do two for loops in my class, however, I've never done two at the same time before so I'm unsure how to get started.
I know that to get the total number of months I can do this:
Integer numOfMonths = start_date.monthsbetween(end_date)
I know that to create the records I can do something like this:
for(Integer i = 0; i < numOfMonths; i++) {
insert new Revenue_Schedules__c(
Amount__c = amount/numOfMonths,
Date__c = start_date.addmonths(numOfMonths),
);
How do you loop through values in the newMap to get each variable and then loop again to get records to insert?
-=EDIT=-
input example: Revenue record with start_date = 10-1-2016, end_date = 9-1-2017, amount = 1100
output expectation:
12 Revenue Schedule records
* record 1, date = 10-1-2016 amount = 100
* record 2, date = 11-1-2016 amount = 100
* record 3, date = 12-1-2016 amount = 100
ect..