Salesforce Admin Quick Tips

Salesforce Quick Tip – How to Dynamically Render Fields and Buttons on Page Layouts

3 min read

Subscribe on YouTube

Why This Is Useful

Sooner or later somebody is going to ask you to only show a field or a button under certain circumstances. “Only show the Phone field when the Rating is Hot.” That sort of thing.

Historically this meant record types, page layouts, and a slowly growing pile of them. Now it’s a few clicks, no code, thanks to Dynamic Forms and Dynamic Actions.


Dynamic Forms: Conditional Fields

1. Open a record, click the gear, choose Edit Page.
2. Click the Record Detail component on the canvas.
3. In the right hand panel, click Upgrade Now. That converts the old single Record Detail block into individual field components you can control one by one.
4. Click the field you want to control, in this case Phone.
5. Under Set Field Visibility, click Add Filter.
6. Choose the Account’s Rating field, operator Equal, value Hot.
7. Save and activate.

Now Phone appears only when Rating is Hot. No code, no extra page layout, no record type.

That Upgrade Now step is the bit people miss. Until you do it, the Record Detail is one indivisible block and you can’t target individual fields.


Dynamic Actions: Conditional Buttons

Same idea, different component.

1. In the Lightning App Builder, click the Highlights Panel at the top of the page.
2. Click Enable Dynamic Actions (you’ll only see this once).
3. Add the actions you want, then click any one of them.
4. Add a visibility filter exactly as above.

Now that Escalate button only shows on Cases that are actually escalatable, instead of showing to everybody and throwing a validation error when they click it.


What You Can Filter On

More than you’d expect:

Record fields – any field on the record
Device – phone, tablet or desktop
User – their profile, role, or a custom permission
Permissions – standard or custom

That user and permission filtering is the genuinely powerful bit. You can show a Discount Approval button only to people with a specific custom permission, and manage the whole thing through permission sets rather than editing page layouts.


One Important Caveat

This is visibility, not security.

Hiding a field with Dynamic Forms does not stop that user reading it through the API, a report, or a Lightning Web Component. It’s a UI convenience, nothing more.

If a user genuinely must not see a field, that’s field level security on their profile or permission set. Different tool, different layer, and the only one that actually enforces anything. Same distinction I made in my post on profiles and permission set groups.

Use Dynamic Forms to reduce clutter. Use FLS to protect data. Don’t confuse the two.


Full details in the Dynamic Forms documentation. Go declutter a page layout.


Get Coding With The Force Merch!!

We now have a redbubble store setup so you can buy cool Coding With The Force merchandise! Please check it out! Every purchase goes to supporting the blog and YouTube channel.

Get Shirts Here!
Get Cups, Artwork, Coffee Cups, Bags, Masks and more here!


Check Out More Coding With The Force Stuff!

If you liked this post make sure to follow us on all our social media outlets to stay as up to date as possible with everything!

Youtube
Patreon
Github
Facebook
Twitter
Instagram


Salesforce Development Books I Recommend

Advanced Apex Programming
Salesforce Lightning Platform Enterprise Architecture
Mastering Salesforce DevOps

Good Non-SF Specific Development Books:

Clean Code
Clean Architecture