我只有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
有帮助吗?

解决方案

我认为您必须将CCLIST的类型从“对象”更改为“ fusthree__c”。当您尝试写作时,这也将为您提供编译时间检查 ccList[0].SomeNonExistentFieldName__c.

如果您不能这样做,并且真的需要存储结果是通用的对象 - 我相信这应该是sobject?

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top