+ Start a Discussion
lsatonylsatony 

if checked, make different field required

hi there,

 

does anyone know what the rule would be for something like this?  i'm struggling with the code:(

 

  • if this checkbox is checked, make these fields required
  • if this checkbox is unchecked, make these same fields NOT required 


or even better -

 

  • if this checkbox is checked, REVEAL these fields and make them required
  • if this checkbox is unchecked, HIDE these same fields and make them NOT required

 

 

Thanks so much!!

Best Answer chosen by Admin (Salesforce Developers) 
NPMNPM
To check for null on a text field use LEN(field)=0

All Answers

RobertCravRobertCrav

A simple validation rule would suffice

 

and(field 1 = true,

       field 2 = false)

 

then enter in the error and where you want it to display, either at the top of the screen or at the field you want to require.  If you want to require multiple fields, create multiple rules.

lsatonylsatony

thanks so much!

 

this worked for me

 

and(Pilot__c  = true,  Pilot_Start_Date__c = NULL)

 

 

but it seems i can't add multiple AND statements

 

how can I adapt this to make multiple blank fields required if Pilot__c  = true?

 

thanks again:smileyhappy:

RobertCravRobertCrav

You can use comma's to enter multiple fields, and(field 1 = true, field 2=false, field 3 = true....)

 

BUT using an AND function means that all criteria have to be met, and you only have 1 error message, so it would have to be generalized at the top of the screen. 

 

I prefer individual validation rules so I can place the error exactly at the field that needs to be populated.

lsatonylsatony

thanks again.

 

this is crazy - now the rule seems to have stopped working for no reason!  it says there are no errors in the syntax:(:(:(

lsatonylsatony

i'm using this same exact code

 

and(Pilot__c  = true,  Pilot_Start_Date__c = NULL)

 

it worked about 1/2 hour ago, and now it does not.

 

lsatonylsatony

not sure what happened there.  changed the rule to the following and it worked.

 

and(Pilot__c  = true,ISNULL( Pilot_Start_Date__c ) ,  ISNULL( Pilot_End_Date__c ) )

JakesterJakester

BTW, you could simplify this by removing the "=True" checks for the checkbox. One other thing - SF has recently introduced an alternate syntax for And(). For example, you could write the formula as:

 

 

Pilot__c && ISNULL( Pilot_Start_Date__c ) && ISNULL( Pilot_End_Date__c )

 

 

 

 

 

 

 

 

lsatonylsatony

thanks Jakester:)  i tried implementing that syntax with another field in my form.  it says that there are no errors, but it does not work.  any clues?

 

Hardware_Required__c
&& ISNULL( Date_Required_at_Client_Location__c )
&& LEN(Hardware_Type_A__c ) = 0
&& ISNULL(Hardware_Quantity_A__c )
&& ISNULL( Rental_Fee_A_Monthly__c )

 

just for reference - 

 

Hardware_Required__c - checkbox

&& ISNULL(  Date_Required_at_Client_Location__c) - date field

&& LEN(Hardware_Type_A__c ) = 0 - lookup field

&& ISNULL(Hardware_Quantity_A__c ) - number field

&& ISNULL(  Rental_Fee_A_Monthly__c  ) - text field

 


 

 

NPMNPM
To check for null on a text field use LEN(field)=0
This was selected as the best answer
lsatonylsatony
@ NPM - that was it!!  thanks!!:)
lsatonylsatony

Ok, so here is my final validation rule.

 

 

Hardware_Required__c
&& ISNULL(  Date_Required_at_Client_Location__c  )
&& LEN(Hardware_Type_A__c ) = 0
&& ISNULL(Hardware_Quantity_A__c )

 

But it validates even if only ONE of the fields is filled.  I need it to check to make sure ALL of the feilds are filled if Hardware_Required__c = true.  What am I doing wrong?

 

thanks!

JakesterJakester

Replace all of the && with ||

lsatonylsatony
perfect!  THANKS!!!!!!!!!!!!
lsatonylsatony
looks like i need to use combinations of && and || for these validations...
NPMNPM

Based on your what ever your requirement is you need to think through the logic and set up your formula so that it evaluates to "True" when you want the validation rule to trigger.   

 

You said you want to check to make sure ALL of the feilds are filled if Hardware_Required__c = true.  I am more familar with the older syntax so you would want :

 

 

AND( Hardware_Required__c, OR(

ISNULL( Date_Required_at_Client_Location__c ), LEN(Hardware_Type_A__c ) = 0, ISNULL(Hardware_Quantity_A__c ) ) )

 

This should evaluate to True if the checkbox is checked and any of the other three fields are null.  If you like or are more familiar with the newer syntax you still need to setup the formula to trigger the rule when you want to.