Pergunta

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
Foi útil?

Solução

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?

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top