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

Urgent!! Need help in trigger to update date field

I need to write a trigger to update 2 fields 1st anniversary date and 6th annivarsary date. I have a field called evalution date.


As soon i enter this i want 1st anniversary date to update by 1 year and 1 day less.

Second to update 6th anniversary date year +6 and day -1.


I tried this with formula field but using formula i cant ignore leap years eg. When Evalution date is  03/01/2008 (leap year), its not showing me one day before date as - 1 for 1st anniversary. it gets blank in this case.


Please Provide any triiger which can calculate dates according to leap year



Check this...





Magulan D certified Developer.



If this post is your solution, kindly mark this as the solution.




In your trigger, you can simply use Date methods and assign the necessary dates.


For example:


trigger tgrDummy on dummy(before insert){

     for(dummy d :trigger.New){

          if(d.anniversaryDate != NULL){

                 Date firstAnnDate = anniversaryDate.addYears(1) - 1;

                 d.FirstAnniversaryDate = firstAnnDate;

                 Date sixthAnnDate = anniversaryDate.addYears(6) - 1;

                 d.SixthAnniversaryDate = sixthAnnDate;





It's a simple code which fetches the "date value" you will enter on some field. Based on it, it will add a year and six years respectively to FristAnniversaryDate and SixthAnniversaryDate fields respectively. 


Let me know if any questions. Hope it helps!