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
PubNoahPubNoah 

Validation Help -- Making picklist required if a field is populated.

What am I doing wrong here?  I want to make picklist name "Budget_Cap_Interval__c" required if field name "Budget_Cap__c" is populated with any value.  Can you help?

 

 

IF(
AND(
ISPICKVAL(Budget_Cap_Interval__c, "Daily"), 
ISPICKVAL(Budget_Cap_Interval__c, "Weekly"), 
ISPICKVAL(Budget_Cap_Interval__c, "Monthly"), 
ISPICKVAL(Budget_Cap_Interval__c, "Annually"), 
ISPICKVAL(Budget_Cap_Interval__c, "Through Year-End") 
),
(NOT(ISNULL(Budget_Cap__c))), 
TRUE, 
FALSE 
)

IF(

AND(

ISPICKVAL(Budget_Cap_Interval__c, "Daily"), 

ISPICKVAL(Budget_Cap_Interval__c, "Weekly"),

ISPICKVAL(Budget_Cap_Interval__c, "Monthly"),

ISPICKVAL(Budget_Cap_Interval__c, "Annually"),

ISPICKVAL(Budget_Cap_Interval__c, "Through Year-End")

),

(NOT(ISNULL(Budget_Cap__c))),
TRUE,

FALSE

)

 

 

I am getting the dreaded message below:

 

 Error: Incorrect number of parameters for function IF(). Expected 3, received 4
 
Best Answer chosen by Admin (Salesforce Developers) 
SporterSporter

Sigh it's been a long day it seems,  only way I can see the below not working is depending on the field types but I have this odd feeling something else will arrise.

 

 

IF(
ISPICKVAL( Budget_Cap_Interval__c , "")
 &&
NOT(ISNULL( Budget_Cap__c )),
TRUE,
FALSE
)

 

 

All Answers

SporterSporter

You have the same formula in the valdidation rule twice. Also your current validation rule will never trigger due to the AND() function. The way you have it written is saying if Budget_Cap_Interval__c is equal to all those values then give an error but its not possiblt to have the picklist equal to more than one value (unless its a multi-picklist).

 

Anyway I believe this is what you want instead,:

 

 

IF(
OR(
ISPICKVAL(Budget_Cap_Interval__c, "Daily"),
ISPICKVAL(Budget_Cap_Interval__c, "Weekly"),
ISPICKVAL(Budget_Cap_Interval__c, "Monthly"),
ISPICKVAL(Budget_Cap_Interval__c, "Annually"),
ISPICKVAL(Budget_Cap_Interval__c, "Through Year-End")
),
NOT(ISNULL(Budget_Cap__c)),
TRUE,
FALSE
)

 

 

PubNoahPubNoah

Thanks for your reply!  The duplicate was just a copy/paste error.  But the point about the AND() function is a good one.  However, I am still getting an error.

 

Error message:  "Error: Incorrect number of parameters for function IF(). Expected 3, received 4"

 

Here is the formula I have, exactly as you wrote it.

 

 

IF(
OR(
ISPICKVAL(Budget_Cap_Interval__c, "Daily"),
ISPICKVAL(Budget_Cap_Interval__c, "Weekly"),
ISPICKVAL(Budget_Cap_Interval__c, "Monthly"),
ISPICKVAL(Budget_Cap_Interval__c, "Annually"),
ISPICKVAL(Budget_Cap_Interval__c, "Through Year-End")
),
NOT(ISNULL(Budget_Cap__c)),
TRUE,
FALSE
)

 

 

IF(
OR(
ISPICKVAL(Budget_Cap_Interval__c, "Daily"),
ISPICKVAL(Budget_Cap_Interval__c, "Weekly"),
ISPICKVAL(Budget_Cap_Interval__c, "Monthly"),
ISPICKVAL(Budget_Cap_Interval__c, "Annually"),
ISPICKVAL(Budget_Cap_Interval__c, "Through Year-End")
),
NOT(ISNULL(Budget_Cap__c)),
TRUE,
FALSE
)

 

 

SporterSporter

Apologies PubNoah,

 

This is what you need:

 

IF(
OR(
ISPICKVAL(Budget_Cap_Interval__c, "Daily"),
ISPICKVAL(Budget_Cap_Interval__c, "Weekly"),
ISPICKVAL(Budget_Cap_Interval__c, "Monthly"),
ISPICKVAL(Budget_Cap_Interval__c, "Annually"),
ISPICKVAL(Budget_Cap_Interval__c, "Through Year-End")
) &&
NOT(ISNULL(Budget_Cap__c)),
TRUE,
FALSE
)
PubNoahPubNoah

Thanks!  But it didn't work...  It is allowing me to save the record with the "Budget_Cap__C" field populated, but the "Budget_Cap_Interval__C" picklist unpicked.

 

Any other thoughts?  I appreciate your assistance here.

SporterSporter

That'll teach me for not reading your original request and just looking at the formula, so your orginal request was " I want to make picklist name "Budget_Cap_Interval__c" required if field name "Budget_Cap__c" is populated with any value."

 

Right so the code I have is partially correct however there is a much easier way for this to be done:

(This code is saying if the Picklist is Blank and Budget_Cap is populated then give an error. Sorry about the confusion earlier this will teach me to read the quesiton and not examine the code straight away)

 

IF(
ISPICKVAL(Budget_Cap_Interval__c, ""),
) &&
NOT(ISNULL(Budget_Cap__c)),
TRUE,
FALSE
)
PubNoahPubNoah

HA!  Well, we're getting there...  Now I got this error:

 

Error: Syntax error. Found ')'

 

I can see why the error is occurring.  It seems to close a parentheses right before the && value that was never opened.  But I can't seem to figure out how to fix!

SporterSporter

Sigh it's been a long day it seems,  only way I can see the below not working is depending on the field types but I have this odd feeling something else will arrise.

 

 

IF(
ISPICKVAL( Budget_Cap_Interval__c , "")
 &&
NOT(ISNULL( Budget_Cap__c )),
TRUE,
FALSE
)

 

 

This was selected as the best answer
PubNoahPubNoah

Thanks, Sporter!!!  It worked like a charm.

SporterSporter

And only an hour and a half of the day left. Glad to help (finally). =)