You need to sign in to do that
Don't have an account?
SeanCo
How to test for no records returned in 'apex:repeat' statement?
I am trying to figure out how to test fields (included within a apex:repeat) to see if they are blank, or null, and if so display some alternate text (Ex: No records to display) in the table instead of a blank table. Example code snippet below:
<apex:repeat var="auditList" value="{!relatedTo.Site_Audit__r}"> <tr> <td> <apex:outputField value="{!auditList.Audit_Type__c}" /> </td> <td> <apex:outputField value="{!auditList.Delivery_Date__c}" /> </td> <td> <apex:outputField value="{!auditList.Review_Date__c}" /> </td> </tr> </apex:repeat>
Thanks for any help or suggestions!
use apex:outputPanel before rendering apex:repeat code.
Naishadh,
Thanks for your reply. I Tried your suggestion (copy of code below), but receive the following the following error when trying to save/deploy:
Result: FAILED
Problem: Unknown function relatedTo.Site_Audit__r.size. Check spelling.
Is the syntax incorrect? Thanks!
Sorry forget to remove brackets :smileyhappy:.
Naishadh,
I was curious about that myself and actually tried that format after it failed the first time. It still fails with the brackets removed with the following error:
Result: FAILED
Problem: Invalid field 'size' for SObject 'Site_Audit__c'.
Copy of code:
Thanks for all your help!
I don't know what you have written in your controller class but for your reference see the sample code(Already tested).
Naishadh,
I am referencing a Custom Object in this case; it is part of an email template that produces attached PDF. Full example code is below (irrelevant parts omitted):
Given that I am referencing a Custom Object and not a controller class perhaps this method will not work for more? Maybe I need to try a test using one of the custom operators (Ex: ISBLANK or ISNULL)? I gave that a shot, but was unsuccessful unfortunately. Thanks again for all your help on this...truly appreciated!!
I ran into this issue today, here's how I solved it:
<apex:variablevar="auxList"value=""/>
<!-- Workaround for getting the size of a related list -->
<apex:repeatvalue="{!Custom_Object__c.Related_Object__r}"var="r"rows="1">
<apex:variablevar="auxList"value="{!r.id}"/>
</apex:repeat>
<apex:pageMessagesummary="No records "severity="info"strength="2"rendered="{!auxList == ''}"/>
<apex:pageMessagesummary="Has records"severity="info"strength="2"rendered="{!auxList != ''}"/>