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
chris lim 15chris lim 15 

Validation Rules, make fields not mandatory if value to other field iis Opportunity Lost?

I created this Validation Rule that when a user with a specific profile creates or modify an opportunity, he must fill in the Next step fields  
OR(
$Profile.Name ="2F00eb0000000YhB7",
$Profile.Name ="2F00e9E000000ae9h",
$Profile.Name ="2F00eb0000000YhB1",
ISBLANK(NextStep),
ISBLANK( Next_Step_By__c ),)


but I'd like to add a condition: when the opportunity is Lost, these fields are no longer mandatory.

I tried to add this but it doesn’t work

AND(ISPICKVAL( StageName ,"Opportunity Lost"),NOT (ISBLANK( NextStep))),

Do you have any idea ?

 
Best Answer chosen by chris lim 15
Bryan Leaman 6Bryan Leaman 6
When a validation rule evaluates to true, the validation "fails". I believe what is needed is something more like this:
 
AND( NOT(ISPICKVAL(StageName, "Opportunity Lost")),
   OR(
     $Profile.Name = "2F00eb0000000YhB7",
     $Profile.Name = "2F00e9E000000ae9h",
     $Profile.Name = "2F00eb0000000YhB1",
     ISBLANK(NextStep),
     ISBLANK(Next_Step_By__c)
   )
)

So if it's NOT lost, the rest of the validations are evaluated, but if it *is* lost, there's no need to evaluate the "or" conditions at all and the validation passes.

All Answers

SubratSubrat (Salesforce Developers) 
Hello ,

To make the fields not mandatory if the opportunity stage is set to "Opportunity Lost," you can modify your existing validation rule as follows:
OR(
    $Profile.Name = "2F00eb0000000YhB7",
    $Profile.Name = "2F00e9E000000ae9h",
    $Profile.Name = "2F00eb0000000YhB1",
    ISPICKVAL(StageName, "Opportunity Lost"),
    ISBLANK(NextStep),
    ISBLANK(Next_Step_By__c)
)
This rule will check if the user's profile matches the specified profiles, or if the opportunity stage is set to "Opportunity Lost." If any of these conditions are met, the validation rule will pass even if the Next Step fields are blank.

If this helps , please mark this as Best Answer.
Thank you.
Bryan Leaman 6Bryan Leaman 6
When a validation rule evaluates to true, the validation "fails". I believe what is needed is something more like this:
 
AND( NOT(ISPICKVAL(StageName, "Opportunity Lost")),
   OR(
     $Profile.Name = "2F00eb0000000YhB7",
     $Profile.Name = "2F00e9E000000ae9h",
     $Profile.Name = "2F00eb0000000YhB1",
     ISBLANK(NextStep),
     ISBLANK(Next_Step_By__c)
   )
)

So if it's NOT lost, the rest of the validations are evaluated, but if it *is* lost, there's no need to evaluate the "or" conditions at all and the validation passes.
This was selected as the best answer
chris lim 15chris lim 15
Thank you it's working.