You need to sign in to do that
Don't have an account?
Shiva 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
Thanks and Regards,
Shiva RV
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
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. If you want that text field t1 contains values from picklist values use below formula. Let me know if this work :)
Thanks,
Amit Singh.
Thanks
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.
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?
I already tried this in my dev org. :)
Let me know if this helps.
Thanks,
Amit
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
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 !
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
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 !
Even better you can store that in hierarchy custom settings which can be added in validation rule.
RD