For this new Back To Basics post, welcome Akashdeep Arora, Salesforce Evangelist/Consultant at HyTechPro. He started Salesforce journey in 2015. 3X Salesforce Certified Professional, 4X Trailhead Ranger, 5X Trailhead Academy Certified.Founder of #BeASalesforceChamp campaign.
Well, Astro turned 5 recently. So, what’s better than writing something related to Astro. As we all know, when you need a guide, Astro’s there for you.
#Astroturns5 #AppyBirthday #BeASalesforceChamp
Albeit, it sounds easy but still many Developers/Admins gets stuck when they want to make a field required based on one value selected from picklist field. Now, you must be thinking the way to achieve it.
We have different ways to make a field required:
- Required Checkbox while field creation
- Page Layout
- Validation Rule
- Using custom code (Visualforce Page, Lightning component, Apex Trigger to say a few)
But our scenario is little bit different as we want to make it required based on criteria, i.e. selected picklist value must be Astro.
Yay, let’s begin the fun without any delay.
The easiest way to achieve it is to use a validation rule. We have two fields:
- Salesforce Character (a picklist field with values Appy, Astro, Codey, Cloudy and Einstein)
- Astro Mom (a text field).
Here, we go.
After saving the rule, it will look like below:
Well, it’s time for testing. Testing is very necessary for anything. (Wink)
Let’s create a record without giving value in the Astro Mom text field and Select “Astro” from Salesforce Character picklist field like below:
As soon as you click on the Save button, it will give you an error “Please enter Astro Mom“.
Wohoooo, our validation rule is perfect it seems. Now, let’s provide the name of Astro Mom in the text field and click on Save button.
Hurrayyy, the record is saved this time. This is how you can make any field required based on selection of a picklist field value.
Don’t compare yourself with others.
You are best.
#Beasalesforcechamp