function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Gsam1234Gsam1234 

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
6/1/18$300
7/1/18$300
8/1/18$300

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.