0

I have a Validation Rule in which there are 2 picklist fields and one text field. I am writing VR for text field.

The 1st picklist_field1__c which have values like (text -abc, text-def, text-xyz, help, chat, email) and another picklist_field2__c has value "phone" and other one is a simple text_field__c .

I created a VR on text_field__c so that when the picklist_field1__c value is text -abc, text-def, text-xyz, help, chat then only user can enter values manually in text_field__c. If the picklist value is anything else like email the user should get an error entering anything in the text field. This is the VR I wrote but it is having 2 issues.

  1. I need to add null check so that if picklist field1 and picklist field2 are null nobody should be able to edit text field. They should get an error in that case too on text field.
  2. while testing I was changing the picklist value from email to help and text field was set to null and while changing it to value "help" the VR was firing too. It seems like the VR is preventing the wrong field from being edited. For some reason I was able to edit picklist from email to text but i am only getting error when changing the value from email to help.Whenever I am changing the value to help the VR is firing.

How do I fix these 2 issues?

OR(
    AND(
        OR(
            CONTAINS(TEXT(picklist_field1__c), 'text-'),
            ISPICKVAL(picklist_field1__c, 'help'),
            ISPICKVAL(picklist_field1__c, 'chat'),
            ISPICKVAL(picklist_field2__c, 'phone'),

        ),
        ISBLANK(text_field__c)
    ),
    AND(
        ISPICKVAL(picklist_field__c, 'email'),
        NOT(ISBLANK(text_field__c))
    )
)

1 Answer 1

0

As per your issue description, I have tried in my demo org and its working as you requested.

OR(
    AND(
        ISBLANK(Text(Picklist1__c)),
        ISBLANK(Text(picklist2__c)),
        NOT(ISBLANK(Sample_text__c))
    ),

    AND(
        Text(Picklist1__c)='email',
        NOT(ISBLANK(Sample_text__c))
    ),

    AND(
        OR( CONTAINS(TEXT(Picklist1__c), 'text-'),
            Text(Picklist1__c)='help',
            Text(Picklist1__c)= 'chat',
            Text(picklist2__c)= 'phone'),
            ISBLANK(Sample_text__c)
        )
    )
)

10
  • The VR is still firing at the picklist field. Its firing when picklist field is text,help,chat
    – user107526
    Mar 15 at 4:42
  • 1. If you try to enter the value in the text field if both picklist fields are empty then validation rule fire. Mar 15 at 4:55
  • 1. If you try to enter the value in the text field if both picklist fields are empty then validation rule fire, 2. If picklist1 have email value and user tries to enter value in text field it will through error, 3. If user tries to change picklist1 value from email to any other value in the picklist1 and then enter value in text field, it won't give an error and record will save Mar 15 at 5:02
  • 1. This works fine. 2. If Picklist1 has value Email and Picklist 2 has phone It should throw an error. 3. If Picklist 1 contains text or help and picklist 2 = phone The text field shouldnt throw any errror. Also If we change the picklist1 value from email to text or text to email or text to chat The picklist shouldnt throw any error.
    – user107526
    Mar 15 at 5:19
  • Thanks for the update, 2. requirement clear. Can you please confirm if picklist1 have (text -abc, text-def, text-xyz, help, chat) values then text field need make mandatory or not? what about if piclist1 have chat and picklist2=phone? Mar 15 at 5:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.