Print this page

Can you conditionally render elements of a page without Visualforce?

Knowledge Article Number 000187751
Description Can you conditionally render elements of a page without Apex and/or Visualforce? 
Resolution This cannot be accomplished without a Visualforce page. Within a Visualforce page, you can utilize the "rendered" attribute of different elements (pageBlocks, pageBlockSection, etc.), and then have a back-end method on your controller or controller extension that then returns a boolean value determining whether or not this particular element should be rendered. 

Here is an example for a test Account object that looks for a custom column "Tier_1__c" value. If this value is empty or null, we return true, which can be used to conditionally render or not render an element of a front-end VF page:

class AccountExtension { 
Boolean fieldIsNull {get { return Account.CPL_Tier_1__c != '' || Account.CPL_Tier_1__c != NULL) } } 

This could then be called on the VF page: 

<apex:pageBlockSection rendered="{!fieldIsNull}"> 


If you insist on not using Visualforce, the logic of what page sections should render should be determined by using different Record Types and Page Layout assignments, but this will only be controlled by the user's Profile, and not on field values.

promote demote