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
Natasha AliNatasha Ali 

Help with creating a trigger which populates DATETIME fields with weekly dates:

Hi,
So I think I need a trigger to populate dates of Sessions.

We have a custom object called 'Sessions' (child). Sessions are created automatically (via a trigger) for a 'Course' (parent). Now depending on the value of the 'Level' field (on the Course) object, a different number of 'Sessions' are created. (There are different types of sessions, I need it to work for 'Knowledge Module Sessions')

Each of these Sessions has dates which are currently filled manually. Every single session occurs weekly (on the same day i.e every Wednesday). I need help creating a formula to calculate these date and populate them (ALL ARE DATETIME FIELD VALUES).
All dates will be populated based on the Session 1 Planned Date, here is the structure it needs to follow:

If Session Name CONTAINS 'Knowledge Module Session 2' then populate 'Session Planned Date' = Session 1 + 7
If Session Name CONTAINS 'Knowledge Module Session 3' then populate 'Session Planned Date' = Session 1 + 14
If
 Session Name CONTAINS 'Knowledge Module Session 4' then populate 'Session Planned Date' = Session 1 + 21
If Session Name CONTAINS 'Knowledge Module Session 5' then populate 'Session Planned Date' = Session 1 + 28
If Session Name CONTAINS 'Knowledge Module Session 6' then populate 'Session Planned Date' = Session 1 + 35
If Session Name CONTAINS 'Knowledge Module Session 7' then populate 'Session Planned Date' = Session 1 + 42
If Session Name CONTAINS 'Knowledge Module Session 8' then populate 'Session Planned Date' = Session 1 + 49
If Session Name CONTAINS 'Knowledge Module Session 9' then populate 'Session Planned Date' = Session 1 + 56
If Session Name CONTAINS 'Knowledge Module Session 10' then populate 'Session Planned Date' = Session 1 + 63
If Session Name CONTAINS 'Knowledge Module Session 11' then populate 'Session Planned Date' = Session 1 + 70
UNTIL SESSION 80.


Any help is MUCH appreciated :)
Thanks,
Natasha 
Raj VakatiRaj Vakati
I guess you can able to do it with the formula field and no need of any trigger ..

Use CASE function in the formula and try