function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
frank_costanzafrank_costanza 

conditionally display related list button based on user and record status

Hello

 

I am trying to find a way to hide a 'New' button on a related list based on the logged in user role and the status attribute of the current record.

 

For example, I have an object that, once it reaches a certain state and only for certain users, should not be editable or associated with other objects. I can easily hide the edit button on my VisualForce page, but I'm not sure how to hide the 'New' buttons on the related lists.

 

How can I accomplish this?

 

 

Thanks!

IspitaIspita
Hi Frank,
Controlling the standard page components dynamically is bit tricky and mostly a custom VF page whose component visibility is controlled by a combination of factors (in your case status attribute + user role) is the ideal way out.
But in case you want to avoid custom coding and want to take the configuration route I would suggest that all user roles which satisfy your condition should be assigned to a profile which does have the create rights on the object in related list will automatically hide the "New" button.
Does this solve your issue at hand.
Please do let me know.
Thanks and regards,
frank_costanzafrank_costanza

Thanks for the suggestion.

 

Those users can still create objects of that type and relate them to other records, just not to the specific record that has been locked down. So I don' think the the profile approach would work in this case.

 

I'm already using a VF page to display this related list. But I don't know of any way (short of hiding the related list entirely) that I can turn off the 'New' button.

 

I could set a javascript variable that is read on page load and removes the 'New' button from the DOM when necessary. But that is really hackish and I would love to avoid doing that.

IspitaIspita
Cant you embed your related list in a panel or output panel?
In your controller or extension using the combination of factors you mentioned:-
1. User Role
2. Status
evaluate a property or variable of type boolean - in your controller and in your panel set the "rendered" attribute to that value and thus control the visibility.
Ex.g
<apex:outputPanel id="thePanel" layout="block" rendered="{!Your_Controller_Boolean_Variable}">My div</apex:outputPanel>
Does that work for you?