You need to sign in to do that
Don't have an account?
SARI4
How to calculate next meeting date based on given frequency,week and day.
Hi,
I have to write a trigger to calculate next meeting date from today. I have an object which stores input of Frequency(monthly, two month, quaterly), Day(Mon-Fri),Week (Week1 -Week 5). Based on these input how should I calculate the next meeting date from today.
example: If Frequency is "Monthly", Day is "Wednesday" and Week is "Week 3".
then I have to calculate date of next meeting which should be Wednesday of 3rd week of next month.
Please help.
Thanks!
I have to write a trigger to calculate next meeting date from today. I have an object which stores input of Frequency(monthly, two month, quaterly), Day(Mon-Fri),Week (Week1 -Week 5). Based on these input how should I calculate the next meeting date from today.
example: If Frequency is "Monthly", Day is "Wednesday" and Week is "Week 3".
then I have to calculate date of next meeting which should be Wednesday of 3rd week of next month.
Please help.
Thanks!
Please try with below code.
For Reference
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_date.htm
Date nextMeetingDate;
if(Frequency == 'Monthly')
{
nextMeetingDate = System.today().addMonths(1);
}
if(Week !=NULL)
{
Date nextMeetingDateStartMonth = nextMeetingDate.toStartOfMonth();
if(Week == 'Week 1')
{
nextMeetingDate = nextMeetingDateStartWeek.addDays(7);
}
if(Week == 'Week')
{
nextMeetingDate = nextMeetingDateStartWeek.addDays(14);
}
if(Week == 'Week 3')
{
nextMeetingDate = nextMeetingDateStartWeek.addDays(21);
}
if(Week == 'Week 4')
{
nextMeetingDate = nextMeetingDateStartWeek.addDays(28);
}
}
if(Day !=NULL)
{
Date nextMeetingDateStartWeek = nextMeetingDate.toStartOfWeek();
if(UserInfo.getLocale()=='en_US')
{
if(Day == 'Monday')
nextMeetingDate = nextMeetingDateStartWeek.addDays(1);
if(Day == 'Tuesday')
nextMeetingDate = nextMeetingDateStartWeek.addDays(2);
if(Day == 'Wednesday')
nextMeetingDate = nextMeetingDateStartWeek.addDays(3);
if(Day == 'Thursday')
nextMeetingDate = nextMeetingDateStartWeek.addDays(4);
if(Day == 'Friday')
nextMeetingDate = nextMeetingDateStartWeek.addDays(5);
if(Day == 'Saturday')
nextMeetingDate = nextMeetingDateStartWeek.addDays(6);
if(Day == 'Sunday')
nextMeetingDate = nextMeetingDateStartWeek.addDays(7);
}
else
{
if(Day == 'Monday')
nextMeetingDate = nextMeetingDateStartWeek.addDays(7);
if(Day == 'Tuesday')
nextMeetingDate = nextMeetingDateStartWeek.addDays(1);
if(Day == 'Wednesday')
nextMeetingDate = nextMeetingDateStartWeek.addDays(2);
if(Day == 'Thursday')
nextMeetingDate = nextMeetingDateStartWeek.addDays(3);
if(Day == 'Friday')
nextMeetingDate = nextMeetingDateStartWeek.addDays(4);
if(Day == 'Saturday')
nextMeetingDate = nextMeetingDateStartWeek.addDays(5);
if(Day == 'Sunday')
nextMeetingDate = nextMeetingDateStartWeek.addDays(6);
}
}
If it solves your problem, mark it as answer.
Thanks
All Answers
Please try with below code.
For Reference
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_date.htm
Date nextMeetingDate;
if(Frequency == 'Monthly')
{
nextMeetingDate = System.today().addMonths(1);
}
if(Week !=NULL)
{
Date nextMeetingDateStartMonth = nextMeetingDate.toStartOfMonth();
if(Week == 'Week 1')
{
nextMeetingDate = nextMeetingDateStartWeek.addDays(7);
}
if(Week == 'Week')
{
nextMeetingDate = nextMeetingDateStartWeek.addDays(14);
}
if(Week == 'Week 3')
{
nextMeetingDate = nextMeetingDateStartWeek.addDays(21);
}
if(Week == 'Week 4')
{
nextMeetingDate = nextMeetingDateStartWeek.addDays(28);
}
}
if(Day !=NULL)
{
Date nextMeetingDateStartWeek = nextMeetingDate.toStartOfWeek();
if(UserInfo.getLocale()=='en_US')
{
if(Day == 'Monday')
nextMeetingDate = nextMeetingDateStartWeek.addDays(1);
if(Day == 'Tuesday')
nextMeetingDate = nextMeetingDateStartWeek.addDays(2);
if(Day == 'Wednesday')
nextMeetingDate = nextMeetingDateStartWeek.addDays(3);
if(Day == 'Thursday')
nextMeetingDate = nextMeetingDateStartWeek.addDays(4);
if(Day == 'Friday')
nextMeetingDate = nextMeetingDateStartWeek.addDays(5);
if(Day == 'Saturday')
nextMeetingDate = nextMeetingDateStartWeek.addDays(6);
if(Day == 'Sunday')
nextMeetingDate = nextMeetingDateStartWeek.addDays(7);
}
else
{
if(Day == 'Monday')
nextMeetingDate = nextMeetingDateStartWeek.addDays(7);
if(Day == 'Tuesday')
nextMeetingDate = nextMeetingDateStartWeek.addDays(1);
if(Day == 'Wednesday')
nextMeetingDate = nextMeetingDateStartWeek.addDays(2);
if(Day == 'Thursday')
nextMeetingDate = nextMeetingDateStartWeek.addDays(3);
if(Day == 'Friday')
nextMeetingDate = nextMeetingDateStartWeek.addDays(4);
if(Day == 'Saturday')
nextMeetingDate = nextMeetingDateStartWeek.addDays(5);
if(Day == 'Sunday')
nextMeetingDate = nextMeetingDateStartWeek.addDays(6);
}
}
If it solves your problem, mark it as answer.
Thanks