You need to sign in to do that
Don't have an account?
Nevin 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){
if(Trigger.isInsert){
List<Year_Schedule__c> ylst = new List <Year_Schedule__c>();
for(Year__c yr : trigger.new){
Year_Schedule__c ys = new Year_Schedule__c(
Year__c=yr.Id,
Start_Date__c=yr.Start_Date__c ,
Revenue__c=yr.Dynamic_Amount__c,
End_Date__c=yr.End_Date__c);
ylst.add(ys);
}
insert ylst;
}
}
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){
if(Trigger.isInsert){
List<Year_Schedule__c> ylst = new List <Year_Schedule__c>();
for(Year__c yr : trigger.new){
Year_Schedule__c ys = new Year_Schedule__c(
Year__c=yr.Id,
Start_Date__c=yr.Start_Date__c ,
Revenue__c=yr.Dynamic_Amount__c,
End_Date__c=yr.End_Date__c);
ylst.add(ys);
}
insert ylst;
}
}