字段表达式的初始项必须是具体的 SObject:Object
我只有 2 个对象和简单的查询来检索数据。
根据调试输出存储在数组 ccList
中的查询结果是:
(
CustomThree__c:
{
Name=cusmei3 2,
customOne__c=a005000000IwnOPAAZ,
Id=a025000000FsFGQAA3
},
CustomThree__c:
{
Name=cusmei3 1,
customOne__c=a005000000IwnOUAAZ,
Id=a025000000FsFGLAA3
}
)
如您所见 system.debug(ccList[0])
返回:
CustomThree__c:{
Name=cusmei3 2,
customOne__c=a005000000IwnOPAAZ,
Id=a025000000FsFGQAA3
}
但是当我尝试从数组中获取Id
(或其他字段)时,会发生错误。 谁能指出我做错了什么?
代码
Object[] ccList;
ccList = [SELECT id, name, CustomOne__r.name FROM CustomThree__c];
system.debug(ccList);
system.debug('******************************************');
system.debug(ccList[0]);
system.debug(ccList[0].Id); //this one cause the error
I have just 2 objects and simple query to retrieve the data.
The result of query which is stored in array ccList
according to debug output is:
(
CustomThree__c:
{
Name=cusmei3 2,
customOne__c=a005000000IwnOPAAZ,
Id=a025000000FsFGQAA3
},
CustomThree__c:
{
Name=cusmei3 1,
customOne__c=a005000000IwnOUAAZ,
Id=a025000000FsFGLAA3
}
)
As you can see system.debug(ccList[0])
returns:
CustomThree__c:{
Name=cusmei3 2,
customOne__c=a005000000IwnOPAAZ,
Id=a025000000FsFGQAA3
}
But when I try to get Id
(or other field) from the array, the error occurs.
Can anyone point out what am I doing wrong?
code
Object[] ccList;
ccList = [SELECT id, name, CustomOne__r.name FROM CustomThree__c];
system.debug(ccList);
system.debug('******************************************');
system.debug(ccList[0]);
system.debug(ccList[0].Id); //this one cause the error
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您必须将 ccList 的类型从“Object”更改为“CustomThree__c”。当您尝试编写 ccList[0].SomeNonExistentFieldName__c 时,这还会为您提供编译时检查。
如果你做不到,并且确实需要存储结果的对象是通用的 - 我相信这应该是 SObject?
I think you'll have to change the type of ccList from "Object" to "CustomThree__c". This will also give you compile-time checking when you'll try to write
ccList[0].SomeNonExistentFieldName__c
.If you can't do it and really need the object that stores result to be generic - I believe this should be SObject?