You need to sign in to do that
Don't have an account?
wsthesis
Render Related List(s) only if a related record in the list exists
I'm trying to use visualforce to perform the following:
A. Show related lists (and all headings) only if a related record exists.
B. If a related record does not exist, the particular section is not displayed.
I'm trying to use the apex:relatedList tag with the rendered attribute.
Is it possible to check if the list is empty as a boolean expression within visualforce without having to create a custom controller method? I have a working solution, but if I want to add this functionality for all related lists, it's a lot of extra controller code to write.
Thanks in advance.
VisualForce View Page
<apex:page standardController="Account" extensions="AccountHiddenListController">
<apex:detail relatedList="false">
<apex:relatedList list="Opportunities" rendered="{!relatedOpportunitiesExist}">
</apex:relatedList>
</apex:detail>
</apex:page>
<apex:detail relatedList="false">
<apex:relatedList list="Opportunities" rendered="{!relatedOpportunitiesExist}">
</apex:relatedList>
</apex:detail>
</apex:page>
Controller Code:
public class AccountHiddenListController
{
private final Account account;
private boolean relatedOpportunitiesExist;
public AccountHiddenListController (ApexPages.StandardController accountController)
{
this.account = (Account) accountController.getRecord();
}
public boolean getRelatedOpportunitiesExist()
{
if (this.relatedOpportunitiesExist != null)
{
return this.relatedOpportunitiesExist;
}
List<Opportunity> opp = this.getOpportunitiesList();
if (opp.size() > 0)
{
this.relatedOpportunitiesExist = true;
}
else
{
this.relatedOpportunitiesExist = false;
}
return this.relatedOpportunitiesExist;
}
public void setRelatedOpportunitiesExist()
{
}
public List<Opportunity> getOpportunitiesList()
{
if (this.account == null)
return null;
return [select o.id
from Opportunity o
where o.AccountId = :account.id];
}
}
{
private final Account account;
private boolean relatedOpportunitiesExist;
public AccountHiddenListController (ApexPages.StandardController accountController)
{
this.account = (Account) accountController.getRecord();
}
public boolean getRelatedOpportunitiesExist()
{
if (this.relatedOpportunitiesExist != null)
{
return this.relatedOpportunitiesExist;
}
List<Opportunity> opp = this.getOpportunitiesList();
if (opp.size() > 0)
{
this.relatedOpportunitiesExist = true;
}
else
{
this.relatedOpportunitiesExist = false;
}
return this.relatedOpportunitiesExist;
}
public void setRelatedOpportunitiesExist()
{
}
public List<Opportunity> getOpportunitiesList()
{
if (this.account == null)
return null;
return [select o.id
from Opportunity o
where o.AccountId = :account.id];
}
}
Anybody have an update on this one?
The VF Developers Guide has an example, but it does not seem to work.
The example:
<apex:pageBlockTable value="{!results}" var="l"rendered="{!NOT(ISNULL(results))}">
I tried the ISNULL funtion and it did not work.
This is a bit of a cobbled together soloution but it can all be done inside the visualforce page without using any kind of custom apex controller
Since the repeater is only returning one row you are able to disply the related list once...
I know how annoying this is and I spent a good 4 hours on this ;)
Cheers!
--
Ofrag
How about <apex:relatedList list="Related_object__r" rendered="{!Related_object__r.size > 0}"/>
Hey ,
On the standard detail page , I need a button that takes me to the detail record page of the Child record. I figured I could do this with a VF page
But Also want to create a new Child record if the Master doesnot have any child record.
I have been struggling for the last 3 days but cannot figure out a solution.
Please help.
Thanks in advance