Ask Search:
Gislane PaganoGislane Pagano 

I need help to create a validation rule that is going to block for 2 profiles opportunity stage

I am trying to create a validation rule that block my stage closed won and closed lost in my opportuity for two profiles.  I have tried this 

AND(
ISCHANGED( StageName ),
$Profile.Name = "Standard User"
)

Did not worked. Can someone help me. Thank you
Best Answer chosen by Gislane Pagano
Umair JavaidUmair Javaid
Try swapping out Closed Won in the code with the correct stage name for the Closed Won stage in your org. Perhaps it is different?

All Answers

Ashok PatelAshok Patel
Hi @Gislane,
Try this :
AND( 
$Profile.Name <> "Standard Use",
$Profile.Name <> "your secod profile name",
    AND(
    ISCHANGED(StageName), 
        OR( 
            ISPICKVAL(StageName, "Closed Won"), 
            ISPICKVAL(StageName , "Closed Lost") 
        
        )
    )
)
 
Umair JavaidUmair Javaid
Are you wanting to prevent two profiles from selecting the Closed Won and Closed Lost stages? If so, try the following:
 
AND(
    OR(
       ISPICKVAL(StageName, 'Closed Won'),
       ISPICKVAL(StageName, 'Closed Lost')),
    OR(
       $Profile.Name = "Profile 1",
       $Profile.Name = "Profile 2")
)

 
Gislane PaganoGislane Pagano
Thank you @Ashok Patel still let my standard user change the opportunity stage. Anything that I should change here. Thank you
Umair JavaidUmair Javaid
The code I posted above should block the two profiles from selecting Closed Won or Closed Lost, but will still allow the users to change to other stages.
Gislane PaganoGislane Pagano
Hello @Umair Javaid  Thank you so much for your help here. I tested your validation for closed lost it is working but but  for Closed won still let me change it.
Umair JavaidUmair Javaid
Try swapping out Closed Won in the code with the correct stage name for the Closed Won stage in your org. Perhaps it is different?
This was selected as the best answer
Gislane PaganoGislane Pagano
Thank you so much for your help!!!! YOU ARE AWESOME....... FOREVER THANK YOU 
Umair JavaidUmair Javaid
You're very welcome. It is my pleasure.
Steve MolisSteve Molis
I would write it like this
AND(
ISCHANGED(StageName ), 
CASE(StageName, 
'Closed Won',1,
'Closed Lost',1,
0 ) = 1,
CASE($Profile.Name,
"Profile 1",1,
"Profile 2",1,
0) = 1
)

 
Umair JavaidUmair Javaid
@Steve, out of curiosity and sheer ignorance, what is the benefit of writing it that way?
Steve MolisSteve Molis
With CASE you're only making 1 call the the field, instead of making repeated calls to StageName and Profile.Name