I have a query "users want to restrict the Opportunity for everyone So that no one can mark as closed won until that Opportunity does not contain at least 1 Opportunity Product and the closed date is greater than current month then only Salesforce users can mark."

I uaed this validation rule But it is not validating current month

HasOpportunityLineItem = FALSE,
( MONTH( CloseDate ) = MONTH(TODAY()))

what to do?

1 Answer 1


Validation rules trigger when the rule is true. This means that you want to use a combination of AND and OR, and also that you need to check the conditions for when the error should occur. Also, keep in mind that months roll over every year, so you have to take that into consideration as well.

  ISCHANGED( StageName ),
    HasOpportunityLineItem, // It still has a product
    YEAR(CloseDate) < YEAR(TODAY()), // Was in a previous year
    AND( // In this year, but this month or earlier
      YEAR(CloseDate) = YEAR(TODAY()),
      MONTH(CloseDate) <= YEAR(TODAY())

Note that I'm reading from your "English description" of the problem. I'm not entirely sure it's what your users want (normally, users want at least one product added), but this should be exactly what you asked for, as written.

  • you might want to add ISCHANGED(x) / ISNEW() checks, otherwise it will "freeze the opportunity" after the month, wouldn't it? (unless that is what is expected) Commented Mar 14, 2021 at 10:44
  • @SergioAlcocer I don't disagree with that assessment. I've added it.
    – sfdcfox
    Commented Mar 14, 2021 at 13:34

You must log in to answer this question.

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