How to Dynamically Require Fields Using Salesforce Dynamic Forms

Ever since Salesforce released Dynamic Forms I’ve been playing around with ways to use this to improve the user experience. Especially since this was released for standard objects like Account and Opportunity, I’ve been trying to find ways that can make both my life as an admin and a User’s life easier. A common use case that I came across lately, a lot of times people will want to require certain fields be filled out after a certain stage of an opportunity. I want to demo one of these examples with both how it used to be done and how it can be done using Dynamic Forms in a way that I think is slicker.

>> Related: [Salesforce Package] Stamp UTM Parameters on Campaign Members <<


Video transcript:

In this example, I have a field that’s just a look-up to a Contact, called Contract Signer.

And this is required when the Opportunity is Closed Won. Obviously, we can’t have a Closed Won Opportunity if we don’t know who’s going to sign the contract. So typically, this would’ve been accomplished by creating a validation rule that would look something like this:


And then from a user perspective, that would look something kind of like this. I’d go to mark my Opportunity as Closed Won, hit save, and then I’d see that error telling me that this is required. Why this kind of sucks, in my opinion, is that if I’m a user, when I go to move this to Closed Won, there’s no visual indicator to me that this is now required. I just have to kind of know that. While there are ways to address that in the Path a little bit… it’s just kind of kludgy in my opinion.

So how this can be accomplished in dynamic forms is a little bit slicker User interface in my opinion, where, okay, I move to Closed Won, and now you see that this shows as being required. I can populate it, save, and move on with my life. Hooray, exciting.

Behind the scenes, what this looks like is really quite basic. So I’m going to open up my Lightning App Builder here, look at the page. Navigate to my Dynamic Forms tab, and you can see in this Field section, I actually have the Contract Signer field in two different places. This first one here is conditionally visible and has no UI behavior. And this is for if the stage of the record is anything but Closed Won because this is only required when it’s Closed Won. And then this other instance of Contract Signer that I have set to a required UI behavior when the stage is Closed Won. So behind the scenes, what this doing is once I change the stage to Closed Won, this one disappears, this one shows up and is indicated as required.

Now this doesn’t help if you allow your Users to update the stage from the Path, which may mean you still want to have the validation rule for both Users who are updating via the Path and potentially automation or API updates that might be doing the same thing, that you still want to require this. But in my opinion, this is a better User experience. And if you wanted to block Users, for example, from updating via the Path, you can do that by hiding this Path update button. Then this effectively becomes just a visual indicator of what’s happening. And then you can also see any Key Fields and Guidance for Success if you have that configured. But that’s pretty much it and hope you find this useful.


Want tips, tutorials, best practices, and other cool stuff delivered to your inbox?  Subscribe to the quarterly Sponge newsletter >

Sponge | Marketing and Revenue Ops

Get a System Audit

Whether you inherited a new instance or just want a second opinion, we'll dive in and benchmark your tech stack.

  • Hidden
  • Hidden
  • Hidden
  • Hidden
  • Hidden

Sponge | Marketing and Revenue Ops

Download Resource

Use this form to recieve your free resource in your inbox today!