+ Start a Discussion
Viktor BakanovViktor Bakanov 

Empty rows after rendered

Hello!
I have a related list on my vf page called Account Number. This page uses standard controller - Account. So on this page i show Account Numbers related list for Account.
To show necessary record, i add the render component. My code below:
<apex:page standardController="Account" showHeader="true">
    
    <apex:pageBlock title="{!account.name}">
      <apex:pageBlockSection title="Account Numbers" columns="1">      
        <apex:pageBlockTable title="Account Numbers" var="acnum" value="{!account.Account_Numbers__r}" border="1" cellpadding="4" cellspacing="1" width="100%">
            <apex:column >
                <apex:facet name="header">Action</apex:facet>
                <apex:OutputLink value="{!$Action.Account_Number__c.Edit}" rendered="{!acnum.Status__c ='Created'}">Edit</apex:outputLink>
                <apex:OutputText value=" | " rendered="{!acnum.Status__c ='Created'}"> </apex:OutputText>
                <apex:OutputLink value="{!$Action.Account_Number__c.Delete}" rendered="{!acnum.Status__c ='Created'}">Del</apex:outputLink>
            </apex:column>        
            <apex:column >
                <apex:facet name="header">Name</apex:facet>
                <apex:OutputLink value="https://cs87.salesforce.com/{!acnum.id}" rendered="{!acnum.Status__c ='Created'}">{!acnum.Name}</apex:OutputLink>
            </apex:column>
            <apex:column >
                <apex:facet name="header">Account #</apex:facet>
                <apex:OutputText value="{!acnum.Account_No__c}" rendered="{!acnum.Status__c ='Created'}"/>
            </apex:column>
            <apex:column >
                <apex:facet name="header">Status</apex:facet>
                <apex:OutputText value="{!acnum.Status__c}" rendered="{!acnum.Status__c ='Created'}"/>
            </apex:column>            
            <apex:column >
                <apex:facet name="header">Trading Account</apex:facet>
                <apex:OutputText value="{!acnum.Account_Number_Old__c}" rendered="{!acnum.Status__c ='Created'}"/>
            </apex:column>
            <apex:column >
                <apex:facet name="header">Account #</apex:facet>
                <apex:OutputText value="{!acnum.Account_No__c}" rendered="{!acnum.Status__c ='Created'}"/>
            </apex:column>
            <apex:column >
                <apex:facet name="header">Markets</apex:facet>
                <apex:OutputText value="{!acnum.Markets__c}" rendered="{!acnum.Status__c ='Created'}"/>
            </apex:column>
            <apex:column >
                <apex:facet name="header">TCA Settlement Account</apex:facet>
                <apex:OutputText value="{!acnum.TCA_Settlement_Account__c}" rendered="{!acnum.Status__c ='Created'}"/>
            </apex:column>                
            <apex:column >
                <apex:facet name="header">Trading Account Type</apex:facet>
                <apex:OutputText value="{!acnum.Trading_Account_Type__c}" rendered="{!acnum.Status__c ='Created'}"/>
            </apex:column> 
            <apex:column >
                <apex:facet name="header">Account Setup With</apex:facet>
                <apex:OutputText value="{!acnum.Account_Setup_With__c}" rendered="{!acnum.Status__c ='Created'}"/>
            </apex:column> 
            <apex:column >
                <apex:facet name="header">Record Type</apex:facet>
                <apex:OutputText value="{!acnum.RecordType.Name}" rendered="{!acnum.Status__c ='Created'}"/>
            </apex:column>
            <apex:column >
                <apex:facet name="header">Login</apex:facet>
                <apex:OutputText value="{!acnum.Login__c}" rendered="{!acnum.Status__c ='Created'}"/>
            </apex:column>                                                                                             
        </apex:pageBlockTable>
      </apex:pageBlockSection>

This is work for me pretty good, but the table shows now empty rows. See the picture:
Empty rows
It seems there two records, that doesn't meet the criteria of rendered component.
So how can i hide this empty rows from the related list?
Best Answer chosen by Viktor Bakanov
Stefan AbramiukStefan Abramiuk
VIctor,
what is the output aftrer your update?
 
Let's make you code more simple.
 
<apex:page standardController="Account"  extension="Contrller" showHeader="true">

<apex:pageBlockTable title="Account Numbers" var="acnum" value="{!relatedAccountNumbers}" border="1" cellpadding="4" cellspacing="1" width="100%" >
 
public with sharing class Contrller{
	private Id current_Acc_Id;

    public Contrller(ApexPages.StandardController controller) {
		current_Acc_Id = controller.getRecordId();
    }
	
    public List<Account_Number__c> getRelatedAccountNumbers(){
        List<Account_Number__c> conList = [SELECT Status__c, Name, Id FROM Account_Number__c WHERE Account__c = :current_Acc_Id AND Status__c  = 'Created']; //not sure about account relation name
        return conList;
    }
}

 

All Answers

Stefan AbramiukStefan Abramiuk
Hi Victor,

on your page you're hiding only fields not whole rows. That's why there are empty rows. To filter list of records you need to have extension controller and do it in APEX i.e. quering out only those with status = 'Created'.
Viktor BakanovViktor Bakanov
Hi Stefan,
Thanks for response!
I have write apex class and put it as extension, but it doesn't works
public with sharing class contrller {
Public id Current_Acc_Id;

    public contrller(ApexPages.StandardController controller) {
    Current_Acc_Id = controller.getRecord().id;
    }

    public List<Account_Number__c> getrelatedAccountNumbers(){
        List <Account_Number__c> conList = New List<Account_Number__c>();
        for(Account acc:[select id,name,status__c, (select status__c, name, id from Account_Numbers__r) from Account where Status__c='Open']){
           for(Account_Number__c con:acc.Account_Numbers__r)
               conList.add(con); 
        }
        return conList;
    }
}

 
Stefan AbramiukStefan Abramiuk
VIctor,
what is the output aftrer your update?
 
Let's make you code more simple.
 
<apex:page standardController="Account"  extension="Contrller" showHeader="true">

<apex:pageBlockTable title="Account Numbers" var="acnum" value="{!relatedAccountNumbers}" border="1" cellpadding="4" cellspacing="1" width="100%" >
 
public with sharing class Contrller{
	private Id current_Acc_Id;

    public Contrller(ApexPages.StandardController controller) {
		current_Acc_Id = controller.getRecordId();
    }
	
    public List<Account_Number__c> getRelatedAccountNumbers(){
        List<Account_Number__c> conList = [SELECT Status__c, Name, Id FROM Account_Number__c WHERE Account__c = :current_Acc_Id AND Status__c  = 'Created']; //not sure about account relation name
        return conList;
    }
}

 
This was selected as the best answer
Stefan AbramiukStefan Abramiuk
One more thing in SELECT query please add all fields used on page.
Viktor BakanovViktor Bakanov
Great!
Thank you a lot, Stefan! It work's!