I want to only a show a checkbox field in a page layout if a custom setting is false. What would be the best way to do this? I would be much more comfortable editing a VF page. Is there a way to edit page layouts as VF pages ? I'm not seeing anything in the developer console. This idea seems to be what I need, but apparently is not yet available. I would be comfortable doing this in apex/vf but I'm not sure how to get there.
There are some low-code ways to approach this if you're willing to interpret the requirement a bit.
You can add a formula field to the object that references a Hierarchy Custom Setting (List Custom Settings are not supported) and renders either the underlying field value or a blank:
IF($Setup.My_Custom_Setting__c.Should_Show_Field__c, Real_Field__c, "")
You'd still get whatever value you assign as the label of the formula field on the layout, but the presence or absence of the real field value would be dictated by the formula referencing the Custom Setting.
If you want conditional editability, or need to have no trace of the field displayed at all (including the label), you will need to write a custom Visualforce page and embed it into the page layout.
Additionally, if the Custom Setting is granting a permission, you may wish to use Custom Permissions instead. You can also reference these in a Validation Rule if you can live with the field being rendered and only editable with the permission granted, for a no-code solution.
Yes, you can override a detail page using Visualfoce.
- From the object management settings for accounts, go to Buttons, Links, and Actions.
- Click Edit next to View.
- In the Salesforce Classic section, select Visualforce page.
- From the Visualforce page drop-down list, select tabbedAccount. Click Save.
Just make sure that your VF page uses the standard controller for your object and create an extension to store any custom code. In your case, the code to bring in the setting.
VF Tags that will help you
apex:detail - creates an exact clone of the page layout. While I don't think you'll want to use this, it could be useful to know about. The benefit being that the record type to page layout is honored. If you don't use this, that's something you'll have to code yourself. This tag has many customization options associated with it. Reference
apex:relatedList - Creates a copy of a specific related list on the page
<apex:relatedList list="Contacts"/>. Reference. Note: this tag does not support all lists.