1

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}',
              '/{!acc.Id}/m?retURL=%2F{!acc.Id}&isAjaxRequest=1').show();">{!acc.Name}</a>
        </apex:repeat>
    </apex:form>
</apex:page>

Apex:

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?

3
+25

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

Visualforce

<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/>
                  </apex:outputPanel>
            </apex:repeat>
    </apex:form>
</apex:page>

Output

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.

Output

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

eliminating null

| improve this answer | |
  • 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 May 25 '17 at 15:02
  • @Pavantej, find the updated answer and code, to handle blank part. – Santanu Boral May 25 '17 at 16:28
0

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.

| improve this answer | |

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.