Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in Salesforce by (11.9k points)

I am trying to figure out how to test fields (included within an 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. The existing 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>

So in pseudo-code, I am looking for a test such as:

IF RELATED RECORDS FOUND FOR APEX:REPEAT PERFORM FOLLOWING:

<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>

ELSE IF NO RELATED RECORDS PERFORM FOLLOWING:

<tr>

    <td>

    No records to display.

    </td>

</tr>

Thanks in advance for the help!

1 Answer

0 votes
by (32.1k points)
edited by

Try wrapping up your code in higher page element and then use the attribute rendered. 

In case, you're looking for some trick to solve this, follow this:

<apex:pageBlock rendered="{!AND(NOT(ISNULL(auditList)),auditList.size>0)}">

    Stuff is in, put "repeat" tag here.

</apex:pageBlock>

<apex:pageBlock rendered="{!OR(ISNULL(auditList),auditList.size=0)}">

    No records to display.

</apex:pageBlock>

Want to become a Salesforce expert, join Salesforce Online Training now! 

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...