System.SObjectException:通过 SOQL 检索 SObject 行,而不查询请求的字段:
我有一个名为 Technology__c
的自定义对象和名为 AccountTechnologies
的联接对象,它是 Account 和 Technology__c 之间的联接对象。因此 AccountTechnologies 具有来自双方的主详细信息关系。 我在 Technology__c
中添加了一个 count__c
汇总摘要字段来获取计数但是当我在视觉力页面中访问它时,出现以下错误
System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Technology__c.count__c
以下是Visualforce页面代码
<apex:pageBlockTable title="Technologies" value="{!AllTechnologies}"
var="t">
<apex:column value="{!t.Name}" headerValue="Technologies" />
<apex:column value="{!t.count__c}" headerValue="Count" width="20%">
</apex:column>
</apex:pageBlockTable>
I have a custom object called Technology__c
and join object called AccountTechnologies
which is a join object between Account and Technology__c .So AccountTechnologies has a master detail relationship from both sides.
I have added a count__c
roll-up summary field in the Technology__c
to get the count But when i access it in the visual force page I get the following error
System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Technology__c.count__c
The following is the visualforce page code
<apex:pageBlockTable title="Technologies" value="{!AllTechnologies}"
var="t">
<apex:column value="{!t.Name}" headerValue="Technologies" />
<apex:column value="{!t.count__c}" headerValue="Count" width="20%">
</apex:column>
</apex:pageBlockTable>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将
Count__c
字段添加到自定义控制器中的查询中。-- 编辑 --
如果您要查询 Technologies,查询将如下所示:
[Select Id, Name, Count__c From Technology__c];
如果您要查询连接对象,则需要使用子查询来查询关系。您可以检查 Technology 或 AccountTechnologies 对象定义(应用程序设置 > 创建 > 对象),然后单击主详细信息字段以查找子关系名称。将
__r
添加到该关系名称以查找要从中进行子查询的对象。要将
Technology__r
值获取到另一个对象中,您可以在帐户上使用getSObjects()
方法。此文档底部有一个很好的示例。另外,请查看自定义控制器文档了解更多信息信息。
You'll need to add the
Count__c
field to your query in your custom controller.-- Edit --
If you're querying off of Technologies, the query would look like this:
[Select Id, Name, Count__c From Technology__c];
If you're querying off of a junction object, you would need to query the relationship using a subquery. You can check the Technology or AccountTechnologies object definition (App Setup > Create > Objects) and click the Master-Detail field to find the Child Relationship Name. Add an
__r
to that relationship name to find what object to subquery from.To get the
Technology__r
values into another object you would use thegetSObjects()
method on the Account. This documentation has a great example at the bottom.Also, check the custom controller documentation for more information.