+ Start a Discussion

How to create a trigger for a child object of Opportunity that splits revenue by month

I have a custom object called Revenue Schedule that is a child object of Opportunity. The Opportunity has custom fields "Start Date" and "End Date." The child object needs to have a record for each month within the Start Date and End Date, with the proportional amount of Revenue. 

For example, if Opportunity XYZ has Amount of $900, with Start Date of 6/15/18 and End Date of 8/15/18, three rows need to be created:
Schedule DateRevenue

The same holds true if the Start Date and End Date are not evenly split across months. For example, Start Date of 6/28/18 and End Date of 7/5/18. Since 3 days are in June and 5 in July, the record for 6/1/18 would be 3/8 * Opportunity Amount. The record for 7/1/18 would be 5/8 * Opportunity Amount. I am looking for help building the trigger to support the creation of these Revenue Schedule records. Thank you.