+ Start a Discussion
Kitty BarnesKitty Barnes 

Need Help writing a validation rule

I am new to writing validation rules and am stuck.  I need to write a rule so that a person can not change a project status to active unless a picklist field called foundation type is filled out. This would only apply to projects that fall within certain departments.

User-added image
 
Best Answer chosen by Kitty Barnes
Maharajan CMaharajan C
Hi Kitty,

You have to write the validation rule like below:
 
AND( 
ISPICKVAL(Project_Status__c, "Active"),
ISBLANK(TEXT(Foundation_Type__c)),
OR(
ISPICKVAL(ProjDept__c, "Custom"), 
ISPICKVAL(ProjDept__c, "Commercial"), 
ISPICKVAL(ProjDept__c, "Addition")
)
)

Thanks,
Maharajan.C

All Answers

ANUTEJANUTEJ (Salesforce Developers) 
Hi Kitty,

I don't think you would be able to show an error on standard functionality the validation rule only kicks in when the record is about to be saved. You can try checking the below thread  best answer:
>> https://salesforce.stackexchange.com/questions/213783/restrict-a-picklist-field-value-if-a-different-field-on-same-object-false

Answer:

You can use a simple validation rule, if your preference is to surface an error. (You've tagged your question validation-rule). Something like

ISPICKVAL(My_picklist__c, 'RESTRICTED_VALUE') && NOT(Other_field__c)
This assumes that Other_field__c is a checkbox field.

Note, however, that this doesn't disable the entry in the picklist user interface: it simply prevents a record from being saved with this combination of data points.

Alternately, you can make a checkbox field the controlling field (https://help.salesforce.com/articleView?id=sf.fields_defining_field_dependencies.htm&type=5) of your picklist. This would allow you to determine which picklist choices show up at all based on the checkbox's selection state.

Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.  

Thanks.
Malni Chandrasekaran 2Malni Chandrasekaran 2
Hi Kitty,
You have to use the logical operator AND or OR to connect the conditions. 

AND(
condition1,
condition2,
condition3
)

Hope this helps!
 
Maharajan CMaharajan C
Hi Kitty,

You have to write the validation rule like below:
 
AND( 
ISPICKVAL(Project_Status__c, "Active"),
ISBLANK(TEXT(Foundation_Type__c)),
OR(
ISPICKVAL(ProjDept__c, "Custom"), 
ISPICKVAL(ProjDept__c, "Commercial"), 
ISPICKVAL(ProjDept__c, "Addition")
)
)

Thanks,
Maharajan.C
This was selected as the best answer
frsdwf gvrfdegfrsdwf gvrfdeg
Try to add new conisditons. I'm using the same script for my website (https://iriveramerica.com/) that hosted on WordPress.
Samiha LeeSamiha Lee
Option to choose the writer independently. If you are thinking about buying an essay https://samedaywriting.com/, it will be wise to know more about the person who writes your paper.