You need to sign in to do that
Don't have an account?
Amn12345
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
https://sites.google.com/site/infallibletechie/trigger-to-update-the-date-field-one-day-less-than-to-next-year
Check this...
cheers
Regards,
Magulan D
Salesforce.com certified Force.com Developer.
SFDC Blog
SFDC Site
If this post is your solution, kindly mark this as the solution.
Hi,
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!