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
Preet KaurPreet Kaur 

Picklist / Checkbox Validation Rule

Hi, I'm new to salesforce and would appreciate any help! I've not done very many validation rules either.

If the 'Break Penalty inc. VAT' checkbox is checked and the 'Break Penalty Paid' picklist value is "Yes" an amount must be entered in the 'Break Penalty' field. Allowing the record to save. The formula should also work when the checkbox is checked and an amount is entered in the 'Break Penalty' field, the rule should fire telling the user to state whether the penalty has been paid in the 'Break Penalty Paid' picklist field. ('Yes' or 'No')

The current formula I have is:

AND( ISPICKVAL( Break_Penalty_Paid__c , 'Yes') || Break_Penalty_inc_VAT__c = TRUE && ISBLANK( Break_Penalty__c ) )

I am trying to save the record but I'm getting an error message..below..
User-added image

Any Help is Appreciated!! Thanks
logontokartiklogontokartik
Hello Preet

Can you try the below. So I basically combined both the validations you were asking about, but if you want 2 seperate validation rules, you can take the OR part and split out into two.

IF(OR(AND(ISPICKVAL( Break_Penalty_Paid__c , 'Yes'), Break_Penalty_Inc_VAT__c, ISNULL( Break_Penalty__c )),(AND ( NOT(ISNULL(Break_Penalty__c)),Break_Penalty_Inc_VAT__c,TEXT(Break_Penalty_Paid__c)!= "YES"))),true,false)


If you want two validations


Validation 1 : 

IF(AND(ISPICKVAL( Break_Penalty_Paid__c , 'Yes'), Break_Penalty_inc_VAT__c, ISNULL( Break_Penalty__c )),true,false)

Validation 2 : 

IF((AND ( NOT(ISNULL(Break_Penalty__c)),Break_Penalty_inc_VAT__c,TEXT(Break_Penalty_Paid__c)!= "YES")),true,false)

Hope this helps

Preet KaurPreet Kaur
Hi logontokartik, 

Thank you for your response on this. I have tried it as one validation rule and it allows the record to be saved however, when tresting in other scenarios, I get an error message below: 

User-added image

Also, when ONLY checking the checkbox, the formula allows the record to save. Which I was hoping for it not to do that. As an amount must be entered in 'Break Penalty' if the checkbox is true. 


Preet KaurPreet Kaur
**testing
Preet KaurPreet Kaur
User-added image
I am also able to save the record without entering an amount in 'Break Penalty' if the picklist field value is 'yes'. 

Just wondering if it can actually be done in one validationr ule or does it have to be 2? 
logontokartiklogontokartik
Ok. I tested it in my developer org and its working as original req you posted. 

IF(OR(AND(ISPICKVAL( Break_Penalty_Paid__c , 'Yes'), Break_Penalty_Inc_VAT__c, ISNULL( Break_Penalty__c )),(AND ( NOT(ISNULL(Break_Penalty__c)),Break_Penalty_Inc_VAT__c,TEXT(Break_Penalty_Paid__c)!= "YES"))),true,false)

The validation is
1. if checkbox is checked and picklist is "yes", you have to have an amount
2. If checkbox is checked and amount entered, the picklist must be yes. 

Let me know if this is what you are looking for. 

Since there are 2 conditions, if you want to have same error message for both conditions, you can write only one rule. 

User-added image

User-added image

User-added image
Preet KaurPreet Kaur
Basically I want the validation rule to
1. if checkbox is checked and picklist is "yes", you have to have an amount
2. If checkbox is checked, you must enter an amount. 
3. If checkbox is checked, picklist is "yes" and amount is i.e. 1000 and save. But then change my mind to picklist "no" it should allow the record to save.  

Is that possible? 
logontokartiklogontokartik
from the 3 conditions above it basically implied that that amount must be entered if the checkbox is checked. I am not sure why you even need to have a picklist "yes" condition.
Preet KaurPreet Kaur
I'm confused myself here, but I did want the validation to work in the above 3 scenarios. 
logontokartiklogontokartik
Maybe this would help,  I am not sure. 

You must first have picklist set to "Yes" (cannot have anything else saved). and then have checkbox and amounts entered, and then if you want you can make the picklist to NO.

This works on PRIORVAL which I am checking "yes". If its more than what you are looking for. then you might need to write a trigger. 

IF(OR(AND(ISPICKVAL( Break_Penalty_Paid__c , 'Yes'), Break_Penalty_Inc_VAT__c, ISNULL( Break_Penalty__c )),(AND ( NOT(ISNULL(Break_Penalty__c)),Break_Penalty_Inc_VAT__c,NOT(ISPICKVAL(PRIORVALUE(Break_Penalty_Paid__c), "Yes"))))),true,false)

Preet KaurPreet Kaur
The previous formula you gave worked better. This formula isn't allowing me to save the record and gives an error. 

User-added image
Preet KaurPreet Kaur
Okay this is all getting a bit too much now, i think I will be fine if the validation rule will fire on the following 2 conditions.

1. if checkbox is checked and picklist is "yes", you have to have an amount
2. If checkbox is checked, you must enter an amount.

What will be the formula for this?
logontokartiklogontokartik
Basically if checkbox is checked you have to have an amount, which is 

IF(AND(Break_Penalty_Inc_VAT__c, ISNULL( Break_Penalty__c )),true,false)