Loading

Salesforce Apex: Hide a Custom List View Button from Specific Profiles

Udgivelsesdato: Jun 9, 2026
Beskrivelse

In Salesforce, custom list view buttons are visible to all users by default and cannot be hidden from specific profiles using declarative configuration alone. To restrict visibility of a custom list view button to certain profiles, a development-based workaround is required. This article covers two approaches: using a Visualforce page to replicate the list view, or adding Apex logic to the button's onclick handler.

Løsning

The following two workarounds allow you to control which profiles can use a custom list view button. Choose the approach that best fits your org's requirements and development resources.

Option 1: Develop a Visualforce Page with Profile-Based Button Visibility

Create a Visualforce page that replicates the list view layout and replaces the list view page for affected users. Within the page, use Apex to evaluate the running user's profile and conditionally display or hide the button using the apex:commandButton rendered attribute.
Note: This approach requires re-querying and re-rendering all list view data and is more complex to implement.

Option 2: Add Profile-Based Apex Logic to the Button's OnClick Handler

Add an Apex-based JavaScript snippet to the button's OnClick property. The snippet checks the running user's Profile ID or Profile Name and either executes the button's intended action or displays a permission-denied message. The button remains visible to all profiles, but only authorized profiles can successfully use its functionality.


Note: In this approach the button is always shown to all profiles but can only be used by authorized profiles.
If you would like to see native profile-based button visibility implemented as a platform feature, you may vote for the related Idea on the Salesforce Trailblazer Community.

Vidensartikelnummer

000384946

 
Indlæser
Salesforce Help | Article