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
maybemedicmaybemedic 

Dependency between a Picklist and Text field

Hello All,
              I am very new to Salesforce just a couple of days old. I am not even a Salesforce resource, but given the responsibility of making some changes to an existing object. We have an object with several fields. The requirement is that if a particular picklist value say, ABC_c is selected then three text fields need to be validated accordingly, i.e if ABC_c picklist is selected, then the user that enters values in these three text fields should enter atleast 10 chars long string, if not an error should be thrown to the user. I can see that we could create dependency between picklists, but this case of a picklist and text field, I am unaware of it. Any help is greatly appreciated. Also, it would be great if someone could point me to a tutorial where I can learn to write these validation rules. Thanks a zillion.
TCAdminTCAdmin
Hello maybemedic,

You will need to build from the validation rule below. It is a validation on two text fields but can be used for more.

AND(
    NOT(ISPICKVAL(Picklist__c, "")),
    OR(
       LEN(Text1__c) < 10,
       LEN(Text2__c) < 10
    )
)
maybemedicmaybemedic
Thanks Chris,
                       I did pretty much the same and validated two text fields.
tmactmac
I dont know if this is the place for me to post this question but I am having the hardest time writing validation rules.  My problem is that the ones for text fields stump me.  How can I write a validation rule to require that if a text field is complete then you must also complete the picklist field that provides additonal informaton?
 
For example ... if the square ft text field is complete then you must require the square ft range picklist...is this possible?
TCAdminTCAdmin

Hello tmac,

You will want to use something like the one below for that validation rule.

Code:
AND(
  LEN(text_field__c) > 0,
  NOT(ISPICKVAL(picklist__c, "square feet"))
)

This checks to see if there is a value in the text field and if the picklist does not contain "square feet" it will give them an error.

tmactmac

Chris,

This is the validation rule that I am using:

AND(LEN( Square_Footage__c ) > 0,
  (ISPICKVAL( " SF_Range_for_Dashboard__c "))

I apologize because I think I missed something when I originally posted, because when I entered the validation rule in your reply I recieved a syntax error so the above validation rule is revised.  So it should read, if the text field is not blank then you must complete the square footage range picklist field.  However, I continue to receive a syntax error. 

I notice that I often get errors that indicate a parenthisis is missing.  I know this is a sidebar but is there any training that you recommend for data validation.  I am pretty new at this.

Thanks so very much for your help.

 

TCAdminTCAdmin
tmac,
 
Your ISPICKVAL() function is in the wrong format. It should be formatted as below to work. You need to have the field's API name and then a comma and then the text value within quotes to function correctly.
 
Code:
ISPICKVAL(picklist_field, text_literal)
Your exact function should appear as the below.
 
Code:
AND(
  LEN( Square_Footage__c ) > 0,
  ISPICKVAL(SF_Range_for_Dashboard__c, "")
)
This will error out if there is a value in the Square_Footage__c field and the SF_Range_for_Dashboard__c field is left blank.