0

I have a field validation for close date on the opportunity object. The goal is that the date cannot be over 4 years ago.

This date field is part of flow, and I noticed that when I did the date exactly four years ago from today's date, opportunity and allocation couldn't be created. Which was a win.

However there's a loophole and i'm not sure how to compensate for it. When I put a date in the past that exceeds today's day date, for instance 19th of july in 2019, today's date is 17th of July,

the validation doesn't work for this, and so the flow goes and creates the records.

this is the field validation I used:

AND( ISPICKVAL( StageName , "Received") , CloseDate <= ADDMONTHS( TODAY() ,-4*12) )

I tried to combine excel with salesforce formulas in making this. I feel like its a frankenstein's monster type of formula :/

1 Answer 1

1

If today's date is July 17th, 2023, then July 19th 2019 is not 4 years ago or more, so your validation rule is working as expected.

If what you're trying to do is prevent that a record be saved if its CloseDate is in that entire calendar year, you can use the following validation rule formula:

ISPICKVAL(StageName, "Received")
&&
YEAR(TODAY()) - YEAR(CloseDate) >= 4
1
  • 1
    Hi Brandon, thank you for repying! Yes, 4 years ago and beyond, and from this formula it looks like you adjusted it to meet it! I will try it, thank you!
    – Jasmine G
    Commented Jul 17, 2023 at 7:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .