function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Glenn Soden 2Glenn Soden 2 

Granular Opp Stage Validation Rule by Profile rule

I know there are many Validation rule solutions out there but not finding one for my use case.  We currently allow certain profiles ability to change Opportunity Stage using all encompassing "AND( ISCHANGED( StageName ), 
$Profile.Name <> "System Administrator) - and adding any other profiles, user id's etc we want to by pass this rule.  This works fine.

New requirment is to keep this but add a profile that can change ONLY certain picklist values on the Opportunity stage.  That is where I am stuck. Was thinking I could add that profile to this rule, then create a new rule specifically for the profile that will have partial ability to change stage.  But the original rule overrides the lower limiting rule for the profile.

How can I acheive limiting picklist values for one profile  (ie keeping what we have but prevnting this new profile from changing to close won, closed lost, etc)  while keeping the current rule bypass in place for the other profiles?  Any help would be appreciated
 
Best Answer chosen by Glenn Soden 2
Kelly Strauch 2Kelly Strauch 2
Sorry for the delay, but I think I've got it.  It finally dawned on me to just break this into two separate validation rules... so give these a shot and let me know if they work.

Here's the first one, which is very similar to what you had originally -- we're just telling also Salesforce to allow the EE Res Sales profile's to make whatever changes it wants to Stage.  (I know that in itself isn't sufficient for what you want, but hang with me):


Name: Block_Restricted_Profiles_from_All_Stages

Description:  Throw an error when anyone except full-access profiles or the EE Res Sales profile tries to change the Opp Stage.

Formula:
AND(
    ISCHANGED(StageName),
    $Profile.Name <> "System Administrator",
    $Profile.Name <> "Profile1",
    $Profile.Name <> "Profile2",
    $Profile.Name <> "EE Res Sales"
   )


Now, with the second one, we'll restrict which Stage values the EE Res Sales profile can use.  The individual stages you list within this one should be the Stages that EE Res Sales are allowed to use.


Name: Enforce_Stages_for_EE_Res_Sales

Description:  Throw an error when EE Res Sales profile tries to change the Opp Stage to something other than their allowed Stage values.  (This will ignore when full-access profiles change the Stage.)

Formula:
AND(
    $Profile.Name = "EE Res Sales",
​    ISCHANGED(StageName),
    OR(
       NOT(ISPICKVAL(StageName, "Received")), 
       NOT(ISPICKVAL(StageName, "Signed Contract Received"))
      ),
   )

All Answers

Kelly Strauch 2Kelly Strauch 2

Try something like this (writing over all my dummy values inside quotation marks):

OR(
   AND(
        ISCHANGED(StageName), 
        $Profile.Name <> "System Administrator",
        $Profile.Name <> "Other Full Access Profile"
      ),
   AND(
        ISPICKVAL(StageName, "Allowed Stage 1"),
        ISPICKVAL(StageName, "Allowed Stage 2"),
        $Profile.Name <> "Partial Access Profile"
      )
  )
Glenn Soden 2Glenn Soden 2
Thank you Kelly this is close - get extra "AND" error cehcking syntax but I'll keep messing around and post back
Kelly Strauch 2Kelly Strauch 2
Blind guess, but I'd recommend double-checking your commas.  Feel free to copy/paste the exact error you're getting if that doesn't help, though.
Glenn Soden 2Glenn Soden 2
First says "Extra comma" at one right before second AND.  Remove that Comma then says extra ")" before second AND again.  Remove that then EXTRA AND error for the second set.
Kelly Strauch 2Kelly Strauch 2

Hmm.  Are you willing to copy/paste your validation rule so I can take a look?  Feel free to take out any values inside the " "s if they're sensitive, but leave everything else intact.

I'm still thinking it's gotta be just a comma or parenthesis out of place somewhere, but unfortunately I can't pinpoint where without looking at what you've got.

Glenn Soden 2Glenn Soden 2
This is it now:  Doesn't like the comma after Profile2),  remove that and doesnlike the ) after Profile2,  remove that and doesnt like AND    Very bizzare.  Can get stuck going incircles lol


AND( ISCHANGED(  StageName  ), 
$Profile.Name <> "System Administrator",$Profile.Name <> "Profile1", $Profile.Name <> "Profile2"),

AND(
ISPICKVAL(StageName, "Received"), 
ISPICKVAL(StageName, "Signed Contract Received"), 
$Profile.Name <> "EE Res Sales "
  )
)
Kelly Strauch 2Kelly Strauch 2

Ah, gotcha -- you just forgot the "or" at the top.  =)  Actually, I'm glad you did because I caught a couple mistakes on my part.  Here's what it should be:
 

OR(
   AND(
       ISCHANGED(StageName), 
       $Profile.Name <> "System Administrator",
       $Profile.Name <> "Profile1",
       $Profile.Name <> "Profile2"
      ),
   AND(
       $Profile.Name = "EE Res Sales ",
       OR(
          NOT(ISPICKVAL(StageName, "Received")), 
          NOT(ISPICKVAL(StageName, "Signed Contract Received"))
         )
      )
  )


That probably looks confusing, but basically you're just telling Salesforce to throw an error if either one of these statements are true:
 1) Throw an error if the Stage changes and the user logged in doesn't have one of those specified/allowed profiles, or
 2) Throw an error if the user logged in has the EE Res Sales profile and the Stage isn't one of those specified/allowed Stage values

Sorry about that.  Hopefully that version will save for you, then test out your scenarios and let me know if I made any other mistakes.  =)

Glenn Soden 2Glenn Soden 2
Hi Kelly - thanks for your help!  This is soooooo close.  If I add profile to first portion (allowing any stage entry) it will then only block the first entry on NOT(ISPICKVALE  ie: recieved - but still allows Signed Contract Received - the second value NOT(ISPICKVAL.  If I don't put the profile in top, the bottom portion does nothing as all entries are blocked.  SO should the profile be in the first portion (allowing any change) then same profile in the bottom portion to prevent entries?  If that is the case, then it does work but only for the first stage value in the NOT(ISPICVAL section.  Can still make change to the second stage in NOT(ISPICKVAL.

ie:
OR(
   AND(
       ISCHANGED(StageName), 
       $Profile.Name <> "System Administrator",
       $Profile.Name <> "Profile1",
       $Profile.Name <> "Profile2"
      ),
   AND(
       $Profile.Name = "Profile1 ",
       OR(
          NOT(ISPICKVAL(StageName, "Received")),   <-------prevents this entry
          NOT(ISPICKVAL(StageName, "Signed Contract Received"))  <---- allows this entry
         )
      )
  )









 
Kelly Strauch 2Kelly Strauch 2
Dang, we'll get this yet.  =)  I'll play with it more later this afternoon and let you know.
Glenn Soden 2Glenn Soden 2
I"m, doing the same.  I'll post if Ican figure it out.  I would think this would be very useful for controlling access to the Opportunity sstage depending on profile etc.  Esp since we use Force and there a various business groups other than just salespeople  ie; it starts as sales then morphs into operations once the deal is signed.  We don't want sales people changing stages that are use for operations
Kelly Strauch 2Kelly Strauch 2
Sorry for the delay, but I think I've got it.  It finally dawned on me to just break this into two separate validation rules... so give these a shot and let me know if they work.

Here's the first one, which is very similar to what you had originally -- we're just telling also Salesforce to allow the EE Res Sales profile's to make whatever changes it wants to Stage.  (I know that in itself isn't sufficient for what you want, but hang with me):


Name: Block_Restricted_Profiles_from_All_Stages

Description:  Throw an error when anyone except full-access profiles or the EE Res Sales profile tries to change the Opp Stage.

Formula:
AND(
    ISCHANGED(StageName),
    $Profile.Name <> "System Administrator",
    $Profile.Name <> "Profile1",
    $Profile.Name <> "Profile2",
    $Profile.Name <> "EE Res Sales"
   )


Now, with the second one, we'll restrict which Stage values the EE Res Sales profile can use.  The individual stages you list within this one should be the Stages that EE Res Sales are allowed to use.


Name: Enforce_Stages_for_EE_Res_Sales

Description:  Throw an error when EE Res Sales profile tries to change the Opp Stage to something other than their allowed Stage values.  (This will ignore when full-access profiles change the Stage.)

Formula:
AND(
    $Profile.Name = "EE Res Sales",
​    ISCHANGED(StageName),
    OR(
       NOT(ISPICKVAL(StageName, "Received")), 
       NOT(ISPICKVAL(StageName, "Signed Contract Received"))
      ),
   )
This was selected as the best answer
Glenn Soden 2Glenn Soden 2
Thanks Kelly-  that was the conclusion I was coming to.  Sometimes easier to just make two rules instead of trying to force everything into one.  Appreciate it!