1

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.

4

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.

  • That formula wont stop the field from being rendered, only it's value wont be rendered. – gNerb Jun 11 '18 at 18:03
  • I'm assuming the "real" field wouldn't be on the page layout in this case. – David Reed Jun 11 '18 at 18:04
  • right but the "fake" field would – gNerb Jun 11 '18 at 18:04
  • 1
    Oh, I see what you mean - yes, the label will show. I'll make that clearer in my answer. Was shooting for some low-code possibilities for OP. – David Reed Jun 11 '18 at 18:05
2

Yes, you can override a detail page using Visualfoce.

  1. From the object management settings for accounts, go to Buttons, Links, and Actions.
  2. Click Edit next to View.
  3. In the Salesforce Classic section, select Visualforce page.
  4. 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.