0

Title says it all. I'm looking to write a validation rule that effectively prevents non-System Admins ($Profile.Name <> "System Administrator") from changing the Amount, Close Date or creating new Opportunities if 15 days have passed since the the quarter. They should also be able to modify/create Opps in the current quarter.

The only real fields that shouldn't be modified after that date are Stage and Amount. They should be able to change everything else related to an opportunity.

I got this:

AND(
$Profile.Name <> "System Administrator", 
$Profile.Name <> "API System Administrator", 
$User.FirstName <> "Aram",
OR(
ISNEW(),
ISCHANGED(CloseDate),
ISPICKVAL( PRIORVALUE(StageName) , "Closed Won"),
ISPICKVAL( PRIORVALUE(StageName) , "Closed Lost"),
ISCHANGED(Amount)),
OR(

And I'm a little lost after that.

3
  • 1
    Seems like you cut off the rule in the middle of your paste job?
    – Adrian Larson
    Oct 12, 2016 at 19:17
  • 1
    You could create a new Locked Record Type and make the layout read only to all profiles except Admins (or grant access to it via permission set) then you'd just need a workflow rule to change Record Type 15 days after quarter ends.
    – dBeltowski
    Oct 12, 2016 at 19:23
  • @AdrianLarson "And I'm a little lost after that."
    – sfdcfox
    Oct 12, 2016 at 20:12

1 Answer 1

1

Some suggestions to make your life easier.

First, go to Setup > Develop > Custom Permissions, create a new permission, which you'll reference in the rule. It could be something like "Edit Time-Locked Opps" or whatever you want to call it.

This means you no longer have to check profile names, and you can assign it via permission sets, too. For example, this rule fragment will return true if the user doesn't have the permission, and thus be denied.

NOT($Permission.Edit_Time_Locked_Opps)

Next, there happens to be a Boolean flag called IsClosed which is set when an opportunity reaches Closed Won or Closed Lost (and any custom closed values you may have). The following fragment returns true when the opportunity is closed, and would prevent edits:

IsClosed

So, ultimately, your rule should look something like:

AND(
  NOT($Permission.Edit_Time_Locked_Opps), 
  IsClosed,
  OR(
    ISCHANGED(Amount), 
    ISCHANGED(CloseDate)
  ),
  OR(
    YEAR(CloseDate) < YEAR(TODAY()-15),
    AND(
      YEAR(CloseDate) = YEAR(TODAY()-15),
      CEILING(MONTH(CloseDate)/4) < CEILING(MONTH(TODAY()-15)/4)
    )
  )
)

Working through this, we see if the user has the custom permission we wrote, then we see if the opportunity is closed (won or lost), if our protected fields changed, and then we see if we count back 15 days, is the resulting year greater than the close date's year. Otherwise, we see if the CloseDate is in the current year, and the FQ is less than the current FQ (again offset by 15 days).

9
  • The second AND clause is just ISCHANGED?
    – Adrian Larson
    Oct 12, 2016 at 20:27
  • @AdrianLarson I meant IsClosed, actually. Thanks for the note.
    – sfdcfox
    Oct 12, 2016 at 20:28
  • I guess if they implement Custom Fiscal Quarters they're stuck with Apex, eh?
    – Adrian Larson
    Oct 12, 2016 at 20:51
  • @AdrianLarson Yeah, there's no formula methods I know of that would allow them to know the fiscal quarter of an arbitrary date.
    – sfdcfox
    Oct 12, 2016 at 20:52
  • @sfdcfox thanks for this - I'll give this a shot tomorrow. I like the idea of using IsClosed - but if we have other stages that are technically closed (e.g. when the donation comes through the door, we technically close the gift, but we use the stage to indicate that it still needs to be won with 'Closed Won - Send Thanks') would that still work? I didn't know about the custom permission - that's awesome!
    – Zakk Tapp
    Oct 13, 2016 at 2:06

You must log in to answer this question.

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