+ Start a Discussion
Cody PiersonCody Pierson 

Setting Close Months to the last day of the month, 3 months from today.

We currently have a process automation set up that sets the Close Date or Opportunities to 90 days in the future using a simple formula.

TODAY() + 90

However, we've recently been asked to always set the Close Date to the last day of the month. I haven't been able to figure out a formula that can add the months, then determine the last day of the month,

Any help would be amazing!
mukesh guptamukesh gupta
Hi Cody,

Please use below code for your solution
 
Date firstDayOfMonth = System.today().toStartOfMonth();

Date lastDayOfMonth = firstDayOfMonth.addDays(Date.daysInMonth(firstDayOfMonth.year(), firstDayOfMonth.month()) - 1);

system.debug('lastDayOfMonth-- '+lastDayOfMonth);

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh
Cody PiersonCody Pierson
Hi Mukesh, 

Thanks for passing that along! I entered the code as-is and it's throwing a syntax error.

User-added image

Also, not sure if this will change anything, but I realized I was a little unclear on my ask. But the goal is to set the Close Date to the last day of the month three months into the future. (i.e. If it was created today, set Close date to Feb. 28, 2022.)

Thanks!
Cody PiersonCody Pierson
Hi there! 

I'm still looking for a solution to the question above. Any insight or assistance would be greatly appreciated!