0 votes
1 view
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 (30.1k points)

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>

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...