function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Displaying custom object fields related to an Account (VF page)


Can you help me out with my Visual Force page;

I have a custom object "Participation" which connects an Account to an other custom object "Lessons". Now I'm trying to collect all the participations of an Account to my VF page. With this page it should be possible to print out the information (date values) when the Account took the lesson. I'm using apex:repeat to iterate through every participation displayed at the Account tab related list. Problem is that with repeat my VF page is full of empty fields. I should be able to display custom field on the VF page only when it has a value. This means that 38 custom fields that my participations object has, should be displayed only ones at my VF page. Account participates only ones to one lesson. 


Explained in a complicated way?  :smileyhappy:

Is it possible to use apex repeat with condition to display only values that are not null? Or is there a better way to do this? 


This is the code:

 <apex:page showHeader="false" standardController="Account" renderAs="pdf">
<p><b><font face="Arial" color="#000080">Header1</font></b></p>
<table border="0" cellspacing="0" cellpadding="0" width="100%" id="table1">
    <td width="60%">
    Account Name:&nbsp;<apex:outputText value="{!Account.Name}"/><br/>
    <td width="40%"><b><font face="Arial"></font></b><br/>
<table border="0" width="100%" cellspacing="0" cellpadding="0" id="table2">
  <apex:repeat value="{!Account.Participations__r}" var="osa">  
       <td width="60%">
           <font face="Arial">Header2:<br/>          
              A1:&nbsp;<apex:OutputField value="{!osa.A_1__c}"/><br/>
              A2:&nbsp;<apex:OutputField value="{!osa.A_2__c}"/><br/>
              A3:&nbsp;<apex:OutputField value=" {!osa.A_3__c}"/><br/>
              A4:&nbsp;<apex:OutputField value=" {!osa.A_4__c}"/><br/>
              A5:&nbsp;<apex:OutputField value=" {!osa.A_5__c}"/><br/>            
              A6:&nbsp;<apex:OutputField value="{!osa.A_6__c}"/><br/>
              B1.1:&nbsp;<apex:OutputField value="{!osa.B_1_1__c}"/><br/>
              B1.2:&nbsp;<apex:OutputField value=" {!osa.B_1_2__c}"/><br/>
              B1.3:&nbsp;<apex:OutputField value=" {!osa.B_1_3__c}"/><br/>
              B1.4:&nbsp;<apex:OutputField value=" {!osa.B_1_4__c}"/><br/>             
              B2.1:&nbsp;<apex:OutputField value="{!osa.B_2_1__c}"/><br/>
              B2.2:&nbsp;<apex:OutputField value="{!osa.B_2_2__c}"/><br/>
              B2.3:&nbsp;<apex:OutputField value=" {!osa.B_2_3__c}"/><br/>
              B2.4:&nbsp;<apex:OutputField value=" {!osa.B_2_4__c}"/><br/>
              B2.5:&nbsp;<apex:OutputField value=" {!osa.B_2_5__c}"/><br/>           
              B2.6:&nbsp;<apex:OutputField value="{!osa.B_2_6__c}"/><br/>
              B3.1:&nbsp;<apex:OutputField value="{!osa.B_3_1__c}"/><br/>
              B3.2:&nbsp;<apex:OutputField value=" {!osa.B_3_2__c}"/><br/>
              B3.3:&nbsp;<apex:OutputField value=" {!osa.B_3_3__c}"/><br/>            
        <td width="40%">
           <font face="Arial">Header2:<br/>          
              B3.4:&nbsp;<apex:OutputField value=" {!osa.B_3_4__c}"/><br/>         
              B3.5:&nbsp;<apex:OutputField value="{!osa.B_3_5__c}"/><br/>
              B3.6:&nbsp;<apex:OutputField value="{!osa.B_3_6__c}"/><br/>            
              B3.7:&nbsp;<apex:OutputField value="{!osa.B_3_7__c}"/><br/>
              B3.8:&nbsp;<apex:OutputField value="{!osa.B_3_8__c}"/><br/>
              B4.1:&nbsp;<apex:OutputField value="{!osa.B_4_1__c}"/><br/>
              B4.2:&nbsp;<apex:OutputField value="{!osa.B_4_2__c}"/><br/>               
              C1:&nbsp;<apex:OutputField value="{!osa.C_1__c}"/><br/>           
              C2:&nbsp;<apex:OutputField value="{!osa.C_2__c}"/><br/>             
              C3:&nbsp;<apex:OutputField value="{!osa.C_3__c}"/><br/>            
              C4:&nbsp;<apex:OutputField value="{!osa.C_4__c}"/><br/>           
              C5:&nbsp;<apex:OutputField value="{!osa.C_5__c}"/><br/>            
              C6:&nbsp;<apex:OutputField value="{!osa.C_6__c}"/><br/>            
              C7:&nbsp;<apex:OutputField value="{!osa.C_7__c}"/><br/>           
              C8:&nbsp;<apex:OutputField value="{!osa.C_8__c}"/><br/>             
              C9:&nbsp;<apex:OutputField value="{!osa.C_9__c}"/><br/>              
              C10:&nbsp;<apex:OutputField value="{!osa.C_10__c}"/><br/>               
              C11:&nbsp;<apex:OutputField value="{!osa.C_11__c}"/><br/>              
              C12:&nbsp;<apex:OutputField value="{!osa.C_12__c}"/><br/>          



Hello again,

I've been searching the solution and found out that "rendered" attribute could be used to set up certain condition.

I've tried this out, but it didn't work. Any comments, help... advice?

    A1:&nbsp;<apex:OutputField value="{!osa.A_1__c}" rendered="{!IF(osa.A_1__c <> null,true,false)}"/><br/>

I think you have put ! in wrong place. Just check


    A1:&nbsp;<apex:OutputField value="{!osa.A_1__c}" rendered="{IF(!osa.A_1__c <> null,true,false)}"/><br/>





thanks for the reply. I tried to edit the code the way you suggested, but it gave an error message. 



Error: The value of attribute "rendered" associated with an element type "apex:outputField" must not contain the '<' character. at line 1






Try this.



<apex:OutputField value="{!osa.A_1__c}" rendered="{!osa.A_1__c != null}"/> --> Display only if it contains value.





Thank you very much! Now I still would like to develop my code to only show 38 custom fields ones. With apex:repeat those custom fields are displayed as many times as there are participations. I need fields to be displayed only ones at the VF page, but the repeat is needed to iterate through every participations.


If the Account has only one participation, the page looks fine, but if there are several (and there will be), the repeat displays every field again and again, just like it would do for instance with opportunityLineItems. My collection of information is different, because every participation needs to be printed (be visible) at the VF page only if it has value at the custom object (source).