gpt4 book ai didi

Salesforce (VisualForce) : How to test for no records returned in 'apex:repeat' statement?

转载 作者:行者123 更新时间:2023-11-30 23:59:04 24 4
gpt4 key购买 nike

我想弄清楚如何测试字段(包含在 apex:repeat 中)以查看它们是空白还是空,如果是,则在表中显示一些替代文本(例如:没有要显示的记录)而不是空白 table 。下面的现有代码片段:

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

所以在伪代码中,我正在寻找一个测试,例如:
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>

在此先感谢您的帮助!

更新响应来自'eyescream'的第一个答案

尝试使用 apex:pageBlock 方法,但在尝试保存/部署时遇到以下错误:

结果:失败 问题: <messaging:emailTemplate> cannot contain <apex:pageBlock>.
现在这是一个电子邮件模板,可生成附加的 PDF(请参阅下面的代码概要)。那么是这种情况吗... pageBlock 不允许在电子邮件模板中使用?谢谢您的帮助!
<messaging:emailTemplate subject="Your requested quote #{!relatedTo.Name}" 
recipientType="Contact"
relatedToType="X360_Contract_Cycle__c">

<messaging:plainTextEmailBody >
.
.
.
</messaging:plainTextEmailBody>

<messaging:attachment renderAs="pdf" filename="{!relatedTo.name}">
.
.
.
<apex:pageBlock rendered="{!AND(NOT(ISNULL(auditList)),auditList.size>0)}">

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

</apex:pageBlock>

<apex:pageBlock rendered="{!OR(ISNULL(auditList),auditList.size=0)}">
<i>No records to display.</i>
</apex:pageBlock>
.
.
.
</messaging:attachment>
</messaging:emailTemplate>

最佳答案

一般来说 - 将您的代码包装在更高的页面元素(如 <apex:pageBlock> )中,然后使用属性 rendered .它是可选的,可用于大多数页面元素,the component reference应该为您提供每个标签支持的完整属性列表。

在你的情况下,我想这样的事情应该可以解决问题:

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

随意尝试语法。我使用了公式编辑器中的函数名称(用于公式字段、验证规则等),但使用普通逻辑运算符,如 &&、||也应该可用。

关于Salesforce (VisualForce) : How to test for no records returned in 'apex:repeat' statement?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3715422/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com