0

以下代码不起作用。错误消息是“编译错误:字段表达式的初始项必须是具体的 SObject:第 8 行第 16 列的 LIST”(返回行是第 8 行)

public String getX(){

    List<Oppoinvoice__c> o = [SELECT  Opportunity__r.Account.Name  FROM Oppoinvoice__c];

    return o.Opportunity__r.Account.Name;    
}
4

1 回答 1

2

您必须指定必须显示的列表条目编号。通过您的查询,您将获得一个列表。而且您的方法必须返回一个字符串。

public String getX(){

    List<Oppoinvoice__c> o = [SELECT  Opportunity__r.Account.Name  FROM Oppoinvoice__c];

    return o[0].Opportunity__r.Account.Name;    
}

或者像这样:

public String getX(){

    String o = [SELECT Opportunity__r.Account.Name FROM Oppoinvoice__c Where Id = 'XXXXXXX'].Opportunity__r.Account.Name;

    return o;    
}
于 2012-12-10T15:41:35.073 回答