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
Shiva RajendranShiva Rajendran 

Validation rule at object level to check if the entered text value contains any one of the picklist field value present on that object

I need to create a validation rule for a object , The validation rule should check if the filled text field value contain the value that is valid for a picklist already present . ie : there are two fields ,one text field t1 and picklist p1 with values (v1,v2,v3) at object level . I want to verify if user entered data on text field t1 as one among the value present in picklist p1. Let me know if this can be done through validation rule itself ? I know it is possible through apex code , but my current requirement is to do it through validation rule. Please do share your knowledge

Thanks and Regards,
Shiva RV
Best Answer chosen by Shiva Rajendran
Akhil AnilAkhil Anil
Hi Shiva,

This cannot be done in a validation rule. The only option is to check for every hardcoded 100 values in the formula which is definitely not the right solution. An apex based validation is your best bet for such scenarios !

All Answers

Amit Singh 1Amit Singh 1
Hi Shiva,

Yes, you can use validation rule. You need to create validation rule on the text field, for example, t1 and enter a formula like below:

If you want the exact match from the picklist values use below formula.
AND(Green_Blue_Revenue__c <> 'Web',Green_Blue_Revenue__c <> 'Other')
If you want that text field t1 contains values from picklist values use below formula.
AND( Not(CONTAINS( Green_Blue_Revenue__c , 'Web')),Not(CONTAINS( Green_Blue_Revenue__c , 'Other')) )
Let me know if this work :)

Thanks,
Amit Singh.
Amit Singh 1Amit Singh 1
Replce the filed with your actual fields :)

Thanks
Akhil AnilAkhil Anil
Hi Shiva,

Is your picklist a multi-select picklist or a single select picklist ? Either way, do you want to compare the text field value with only what's selected in the picklist or with every possible value that can be selected in the picklist ? 

Kindly provide inputs on the above so that we can help you.
Shiva RajendranShiva Rajendran
Yes , that's the requirement @Akhil .It's a single picklist , i want to verify if the text entered in the textbox contain one of the value present in the picklist
Shiva RajendranShiva Rajendran
Hi Amit ,
I want to verify if the text entered in the textbox is one of the valid picklist value . In your code , you mean to verify the text field with each of the picklist value? or will that code work if i replaced  by picklist field?
Amit Singh 1Amit Singh 1
Shiva, Yes it will work you just need to replace the field and values with your field and values. "Green_Blue_Revenue__c" will be replaced by your text field and values like "Web", "Other" will be replaced by your picklist values. 

I already tried this in my dev org. :)

Let me know if this helps.

Thanks,
Amit
Shiva RajendranShiva Rajendran
Thanks Amit for your answer.
What if i have a picklist of size 100 , is there a dynamic way to it rather than i checking for each picklist value manually?

Thanks and Regards,
Shiva RV
Akhil AnilAkhil Anil
Hi Shiva,

This cannot be done in a validation rule. The only option is to check for every hardcoded 100 values in the formula which is definitely not the right solution. An apex based validation is your best bet for such scenarios !
This was selected as the best answer
RD@SFRD@SF
Hi Guys,

I agree with all the comments.
What if we try this.
Create a new long text field on the object you want this to happen.
Say my values in picklist are val1,val2 .... val100.
Update the long text with "val1-val2-val3-........val100" assuming there are not hypens in the picklist values. If there are you can use a different symbol.

So what my approach does is that , all the piclist values are stored in the long text with the hypens to differentiate different values.
And in the validation rule, you use "Contains" function with a NOT function.

Yes the catch here is that every time a picklist value is newly added, deleted or deactivated the long text filed must be updated.
But yes you dont have to write a huge validation rule formula. and is achievable by config itself.
The picklist values can be set as default value for the long text. Thus making it as one time setup.

Hope it helps
RD
 
Akhil AnilAkhil Anil
Hi RD,

The approach that you suggest still won't make it dynamic. As you have rightly mentioned that everytime a picklist value is added or deactivated, you need to update every record in your object with the updated values. So if there are a million records in the object then it means updating each one of them which means there is a lot of legwork. Instead there is no maintenance to be taken care of if the validation is simply taken care at the apex trigger level. That would keep things easy and clean !
RD@SFRD@SF
Hi 

Even better you can store that in hierarchy custom settings which can be added in validation rule.

RD