You need to sign in to do that
Don't have an account?
Jai Suresh
Custom Save button to create multiple related records
This is going to be tricky.
I have two related objects.
ObjOne has two date Fields StartDate, EndDate
ObjTwo has a lookup to ObjOne and Date, a date field
When I save ObjOne, I need to find the number of days between the two dates and create that many ObjTwo records, each populated with a date (starting StartDate till EndDate).
My trouble is with the dates. Any help is welcome.
Thank you
I have two related objects.
ObjOne has two date Fields StartDate, EndDate
ObjTwo has a lookup to ObjOne and Date, a date field
When I save ObjOne, I need to find the number of days between the two dates and create that many ObjTwo records, each populated with a date (starting StartDate till EndDate).
My trouble is with the dates. Any help is welcome.
Thank you
First get the difference between the dates and then iterate loop till that many days.
Example:
Integer diffDays = startDate.daysBetween(EndDate);
List<ObjTwo> obj2List = new List<ObjTwo>();
for(Integer i = 0;i < diffDays; i++){
obj2List.add(new ObjTwo(data = startData.addDays(i) , ObjOne = ObjOne.Id )); // this will start with start date till end date.
}
insert obj2List;
But I failed to mention an important caveat, I have to do this with javascript, that is why I said I am having trouble with dates.
Offtopic: Is there a way to edit our posts?