问题描述
我正在有关standardController的教程,但是我使用预览按钮无法查看帐户的空结果
<apex:page standardController="Account" recordSetvar="accounts" sidebar="false">
<apex:pageBlock>
<apex:pageBlockTable value="{!accounts}" var="a">
<apex:column value="{!a.name}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>
但我确实有记录:
select id,name,industry from Account
where name != null
and industry != null
limit 10
这是空的,所以我没有没有名字的帐户
select id,industry from Account where name = null
鉴于字段名称同时存在于两个对象中,我尝试对联系人使用相同的名称,只是将控制器更改为
standardController="Contact"
编辑:只是为了踢球,现在我尝试了
standardController="Opportunity"
顺便说一句,有关帐户的教程是这样的:https://trailhead.salesforce.com/content/learn/modules/visualforce_fundamentals/visualforce_standard_list_controllers
此帐户的代码非常相似:https://www.youtube.com/watch?v=3NwiOqKLXQQ
解决方法
StandardSetController默认显示最后选择的列表视图。如果您的列表视图具有愚蠢的条件,或者它是“最近查看的”列表,并且您最近没有单击过-是的,那就是空列表。
- 将列表视图更改为所有帐户,然后重新加载页面。
- 或在构造函数中调用
ssc.setFilterId()
以强制执行特定的列表视图。 (到目前为止,您看到的是纯视觉效果,没有Apex) - 我认为,如果您传递URL
&fcf=listviewidhere
,就可以达到相同的效果,类似于经典中的列表视图的工作方式。不过已经有一段时间了,它不是官方方法,您应该使用setFilterId - 或者根据您要查询的确切结果构建StandardSetController。 (将this与
\[SELECT...\].getQuery()
结合起来)