You need to sign in to do that
Don't have an account?

Adding multiple child records after inserting parent record
Hi,
I am an Admin trying to learn how to write a trigger but am totally stumped trying to do this one.
I have a Parent Object: which contains fields for Start Date, Number of Months and Cost. Once this is entered an End Date is calculated (using the Start Date * Number of Months) and also the Cost Per Month is calculated (using the Cost / Number Of Months). Then I have a Child Object I want to insert records into.
What I would like to do is write a trigger which fires after the Parent record is entered to insert a number of Child records. The number of Child records is basically one for each month between the start date and end date and also include the cost per month in each record.
So for example the parent record is; -
Start Date - 01/01/2016
End Date - 01/05/2016
Cost - 1000
Number of months - 4
Cost Per Month - 250
Trigger inserts 4 Child records, one for January starting on the start date then one for february, March and April all with a cost of 250
Later on I want to allow the ability to update these dates on the parent and this refreshed the child records, but one thign at a tme. This sounds wat too complicated for me so any help would be great
Thanks
I am an Admin trying to learn how to write a trigger but am totally stumped trying to do this one.
I have a Parent Object: which contains fields for Start Date, Number of Months and Cost. Once this is entered an End Date is calculated (using the Start Date * Number of Months) and also the Cost Per Month is calculated (using the Cost / Number Of Months). Then I have a Child Object I want to insert records into.
What I would like to do is write a trigger which fires after the Parent record is entered to insert a number of Child records. The number of Child records is basically one for each month between the start date and end date and also include the cost per month in each record.
So for example the parent record is; -
Start Date - 01/01/2016
End Date - 01/05/2016
Cost - 1000
Number of months - 4
Cost Per Month - 250
Trigger inserts 4 Child records, one for January starting on the start date then one for february, March and April all with a cost of 250
Later on I want to allow the ability to update these dates on the parent and this refreshed the child records, but one thign at a tme. This sounds wat too complicated for me so any help would be great
Thanks