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
nickfs92840nickfs92840 

Validation Rule needed for Picklist + Field Type

I have an object where a pick list is setup, and when an item is selected from the pickiest, a % field is required to be filled in with a percentage. 

 

The API's are:

 

Picklist = Local_Type__c
% field = Rate_A__c
% field = Rate_B__c

 

 

Here are some scenarios that may be made during the selection process: 

 

Scenario 1
When Picklist "Local_Type__c" is selected and from the menu selections, "Type 1" is selected, % field "Rate_A__c%" is required. 
 
Scenario 2
When Picklist "Local_Type__c" is selected and from the menu selections, "Type 2" is selected, % field "Rate_B__c" is required. 
 
Scenario 3
When Picklist "Local_Type__c" is selected and from the menu selections, "Type 1 and Type 2" are selected, % fields "Rate_A__c" and "Rate_B__c" are required.  

 

Please help in creating this validation rule for me. Many thanks!

Best Answer chosen by Admin (Salesforce Developers) 
Steve :-/Steve :-/

Okay I'd recommend breaking this out into 3 separate VR's but basically you wanna do something like this:

 

OR(
AND(TEXT( Local_Type__c) = "Type 1",  
ISBLANK(Rate_A__c%)),
AND(TEXT( Local_Type__c) = "Type 2",  
ISBLANK(Rate_B__c%)),
AND(TEXT( Local_Type__c) = "Type 1 and Type 2",  
ISBLANK(Rate_A__c%),ISBLANK(Rate_B__c%)))

 

All Answers

Steve :-/Steve :-/

Is LocalType a Picklist or a MultiPicklist datatype?

nickfs92840nickfs92840

Its a Local Type Field.

 

In Scenario 3, the picklist choice may be "Rate A % and Rate B %", as in it would be a single type selection and not two separate selections. Thank you Steve!

Steve :-/Steve :-/

Hi Nick, that's not a datatype.  The datatype is the "format" of the field (Text, Number, Date, Picklist, Multip Picklist, etc.)

nickfs92840nickfs92840

ha!, ooops, Picklist....

Steve :-/Steve :-/

Scenario 3 that you described is not possible with a Picklist field ->

 

Does the picklist have a single value for ""Type 1 and Type 2""

 

Scenario 3
When Picklist "Local_Type__c" is selected and from the menu selections, "Type 1 and Type 2" are selected, % fields "Rate_A__c" and "Rate_B__c" are required.  
nickfs92840nickfs92840

yes, "Type 1 and Type 2" would be a single selection.

Steve :-/Steve :-/

Okay I'd recommend breaking this out into 3 separate VR's but basically you wanna do something like this:

 

OR(
AND(TEXT( Local_Type__c) = "Type 1",  
ISBLANK(Rate_A__c%)),
AND(TEXT( Local_Type__c) = "Type 2",  
ISBLANK(Rate_B__c%)),
AND(TEXT( Local_Type__c) = "Type 1 and Type 2",  
ISBLANK(Rate_A__c%),ISBLANK(Rate_B__c%)))

 

This was selected as the best answer
nickfs92840nickfs92840

Can you break it up into three different VR's for me? Thanks!!

Steve :-/Steve :-/

Sure, that will cost you 3 times as many beers... 

 

VR1:
AND(TEXT( Local_Type__c) = "Type 1",  
ISBLANK(Rate_A__c))


VR2: 
AND(TEXT( Local_Type__c) = "Type 2",  
ISBLANK(Rate_B__c))

VR3:
AND(TEXT( Local_Type__c) = "Type 1 and Type 2",
OR(ISBLANK(Rate_A__c),ISBLANK(Rate_B__c)))

 

Steve :-/Steve :-/

Nick, are you all set or do you still need help with this? (I'm getting thirsty!)

nickfs92840nickfs92840

Hi Steve! I'm probably going to have about 20 items in the picklist. I used the first VR you provided and it worked well with the 3 selections.

 

Do you think I should have 20 different VRs? Let me know!

Steve :-/Steve :-/

Hi Nick,

It's your call, but I personally like to break things out so it's easier to troubleshoot, but 20 VR's might be more trouble to manage than it's worth.

nickfs92840nickfs92840

Either way, both examples you provided work perfectly! Thank you again!