+ Start a Discussion
Nevin O'Regan 3Nevin O'Regan 3 

Auto Create Custom Schedule Record

Hi guys,

I have a custom object called Year__c which related to the Lease. I have created a related child object called Year_Schedule__c. On the Year__c object there is a Start_Date__c, End_Date__c field, No_Of_Installments__c and Amount__c field. 
I'm trying to get this to behave very similar to the standar ScheduleLineItem.
When a user creates a Year__c record I'd like Year_Schedule__c records to automatically create to capture each month within the Start_Date__c and End_Date__c of the parent Year__c record. I have started this out with the below trigger which is creating the record for me but it is not creating a Year_Schedule__c for each month, it is only creating one Year_Schedule__c record. 

trigger CreateSchedulesOnYear on Year__c (after insert, after update){


    List<Year_Schedule__c> ylst = new List <Year_Schedule__c>();

    for(Year__c yr : trigger.new){

        Year_Schedule__c ys = new Year_Schedule__c(
                    Start_Date__c=yr.Start_Date__c ,

    insert ylst;