How to Conditionally Require Fields on a Page Layout
Jun 08, 2024Super quick tip today...
Have you ever needed to conditionally require a field on a page layout?
Imagine a Lead Source picklist field where one option is Trade Show.
If the Lead Source is set to Trade Show, you might want to require two related custom fields named Event Name and Booth Number to be filled in.
Previously making these fields conditionally required needed a validation rule.
With dynamic forms we can now take another approach.
Through the Lightning App Builder we can add the fields named Event Name and Booth Number to the Lead Record Page twice.
The first field pair will not be required, and we can set the conditional visibility to be Lead Source does not equal Trade Show.
This will be useful for when Sales Reps want to record an Event Name related to the lead for reporting, but the lead wasn't actually from a Trade Show.
The second field pair will be required, and we can set the conditional visibility to be Lead Source equals Trade Show.
This is how we meet our conditional field requirement need.
As soon as a user selects Trade Show from the picklist, the two required fields will show on the screen (and the other two will immediately be hidden).
In effect, only one pair of the two fields is ever visible to the user.
Based on their Lead Source selection, however, the two fields will be required if the end user chooses Trade Show and not required any other time.
An added benefit to this approach is that the end user will see the red star next to the required fields when they are supposed to fill them in.
Which gives a better experience than attempting to save a record and getting a validation error!
Sweet!
Thanks for reading and have a great weekend :)
Nick
SalesforceĀ Saturdays
Join the Salesforce Saturday newsletter. Every Saturday, you'll get 1 actionable tip on Salesforce technology or career growthĀ related to the Salesforce Industry.
We hate SPAM. We will never sell your information, for any reason.