I need to show fields dynamically in mini console view based on the criteria in accounts.

Like if unit potential is greater than zero, I need to display this field in console view. Otherwise, I only need account name to display. Because I need to display multiple fields.

I am displaying default console view in a visualforce page like:

<apex:page controller="PopupTest">
    <apex:form >
        <apex:repeat value="{!Accounts}" var="acc">                            
              <br/>  <a href="/{!acc.Id}" id="{!acc.Id}" onblur="LookupHoverDetail.getHover('{!acc.Id}').hide();
              " onfocus="LookupHoverDetail.getHover('{!acc.Id}', '/{!acc.Id}/m?retURL=%2F{!acc.Id}&isAjaxRequest=1').show();
              " onmouseout="LookupHoverDetail.getHover('{!acc.Id}').hide();" onmouseover="LookupHoverDetail.getHover('{!acc.Id}',


public class PopupTest {
    public List<Account> getAccounts()
        List <Account> accounttList = new List<Account>();
        accounttList = [Select Id, Name,Subcategories__c from Account LIMIT 10];
        return accounttList ;


But is there any possibility to dynamically add fields?

2 Answers 2


For dynamic manipulation of fields you could define a field set and add fields into the field set.

Setup--> Account --> Field Sets

In this example, field set name is judelaw. In the page layout, add your desired fields.

Field Set


<apex:page standardcontroller="Account">
    <apex:form >
            <apex:repeat value="{!$ObjectType.Account.FieldSets.judelaw}" var="field"> 
                  <apex:outputPanel rendered="{!Account[field]<> null}">                           
                      <span  class="label" style="align:right"><b> {!field.label}:</b></span>
                      <apex:outputField value="{!Account[field]}"  /><br/>


field set output

For more information, refer $FieldSet

Update based on comments

If field value is null then the field will not get displayed. For that reason, you need to add rendered condition suitably.


Account Source and Brick No are not displaying as those are blank.

eliminating null

  • But for example if BrickNo is blank it display's right.But i dont want to display if BrickNo is blank is it possible
    – Pavan tej
    Commented May 25, 2017 at 15:02
  • @Pavantej, find the updated answer and code, to handle blank part. Commented May 25, 2017 at 16:28

Rather than hard code query use Fieldset though there is a limitation on the number of fields but enough for mini layout. If you need help to write code with Fieldset let me know.

Using fieldset you can pick fields from fieldset configuration it will give you flexibility.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .