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
Shivani DesaiShivani Desai 

Validation rule on Opportunities Failing

Hi,

I have a validation rule where in am trying to control the opportunity from moving to a 100%(closed won) if the stage is not changed by the legal department. The legal department has to verify some of the documents before the contract is signed. Somehow the sales team is able to change the probability irrespective of the validation.

My validation rule
AND( OR(ISCHANGED( StageName )) , OR( ISPICKVAL( StageName ,"PO/Signed Contract"), ISPICKVAL( StageName,"POC Signed Contract") ), $User.Id<>"005G0000002kon2",$User.Id<>"005G0000002iftc")

Checks if the stagename is changed to either of these  picklist values and whether the user id does not belong to one of these two users.

Can anyone please help me? Am doing something wrong but unable to detect what?
RamuRamu (Salesforce Developers) 
If the User id's are correct then the validation should absolutely throw an error. Did one minor change in the formula, please try out the below formula. Also make sure the validation rule is active. Other than this I cannot think of any reasons why it should not work.

​AND( ISCHANGED( StageName ) , OR( ISPICKVAL( StageName ,"PO/Signed Contract"), ISPICKVAL( StageName,"POC Signed Contract") ), $User.Id<>"005G0000002kon2",$User.Id<>"005G0000002iftc")
Shivani DesaiShivani Desai
Thanks Ramu!

Have checked that the user id's are correct. Am suprised by this as even if the user id's were incorrect, it should not allow others to change the stagename. 

 
RamuRamu (Salesforce Developers) 
True. Even if the user id's are incorrect it should not allow other users to edit.

In the description, you said that users are able to change the probability, is it probability or stagename that the users are able to modify. If it is probability, then yes, as the validation rule is written to check the stagename change, it will not throw any error when only the probability value is changed.
Shivani DesaiShivani Desai
So probability is dependent picklist for stagename. And my users are able to change both. I agree that it will not give any error for probability change but am unable to configure the scenario in validation rules where it checks for "100 %" probability value. Also, we have various record types on opportunities where in the business requirements vary for others. Am afraid that adding a probability change clause will lead to a lot of other checks in the formula.

Thanks,
Shivani

 
RamuRamu (Salesforce Developers) 
Hi Shivani, I just tried the below validation rule on on my test org and it is working perfectly.

AND(ISCHANGED(StageName), ISPICKVAL(StageName,"Closed Won"), $User.Id <> "005900000019OsY")

To troubelshoot your issue, I would suggest setting up a debug log and replicate the issue by logging in as one of the sales users who are currently able to make the changes. You can then review the debug logs and see what is the status of the validation rule (pass or fail)