0

I have to write Validation Rule on Opportunity, it has field Stage with picklist values and Closed Reasons is another field with picklist values. I need to write Validation Rule such that if I select Stage with picklist value and if i try to save the opportunity it has to throw the error, because here without selecting closed reasons i cannot save the opportunity. Also if I select the closed reasons value without the stage being closed lost it must throw me an error.

I have used the following Validation rule:

AND (IsClosed,
NOT(IsWon),
ISPICKVAL( Closed_Lost_Reasons__c  ,""))

which solves the first part of the query but I can still choose a closed reasons even if the stage is not closed lost and it does not throw me an error. Which should throw me an error saying that select a value only if stage is closed lost

Can anyone help in a validation rule that will satisfy both criteria?

0

1 Answer 1

3

It will be like this:

  • if Stage is Closed Lost and Closed Lost Reason is blank

or

  • if Closed Lost Reason is given and Stage is not Closed Lost

then throw the validation error.

(ISPICKVAL(StageName,'Closed Lost') && ISBLANK(TEXT(Closed_Lost_Reasons__c)))
||
(NOT(ISBLANK(TEXT(Closed_Lost_Reasons__c))) && NOT(ISPICKVAL(StageName,'Closed Lost')))

Approach 2

You can make Reason for Closure as dependent picklist of stage.

And when Stage is selected as 'Closed Lost' then picklist values of Closed Lost Reason will be available and make this picklist as required in page layout.

This way, you will have better control.

6
  • It would be more clear for the users to have this on 2 serparate Validation Rules with their own error messages...
    – o-lexi
    Mar 17, 2017 at 20:39
  • no, one is fine, Error message will be During Closed Lost, reason for closure is required. Mar 17, 2017 at 20:41
  • exactly, they will be like: "umm..., I don't have stage set to 'Closed Lost'" - real life example...
    – o-lexi
    Mar 17, 2017 at 20:44
  • Or something more abstract like "Close Lost stages must have a reason and a reason cannot be selected unless Closed Lost" That should be fun :). If you put the error next to the stage field instead of at the top it would make more sense
    – Eric
    Mar 18, 2017 at 3:39
  • Approach 2 is good for this Mar 18, 2017 at 3:46

You must log in to answer this question.

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