Salesforce - 构造函数名称无效错误

发布于 2024-11-28 00:36:11 字数 763 浏览 4 评论 0原文

我正在构建一个控制器来显示 Visualforce 页面上自定义对象的数据。这是我的课程:

public class myController {

    Opportunity opp;
    list<Leg__c> legs;

    public Opportunity getOpp() {
        if(opp == null)
            opp = [select name, Primary_Contact__r.name, Primary_Contact__r.email, Primary_Contact__r.phone from Opportunity
                where id = :ApexPages.currentPage().getParameters().get('id')];
        return opp;
    }
    public getLegs() {
        legs = [select Departure__c, Arrival__c from Leg__c
                where Opportunity__c = :ApexPages.currentPage().getParameters().get('id')];
    }

}

我无法编译它!我不断得到

错误:myController 编译错误:构造函数名称无效:getLegs 位于第 12 行第 12 列

我做错了什么,如何解决?

I'm building a controller to show the data from a custom object on a Visualforce page. Here's my class:

public class myController {

    Opportunity opp;
    list<Leg__c> legs;

    public Opportunity getOpp() {
        if(opp == null)
            opp = [select name, Primary_Contact__r.name, Primary_Contact__r.email, Primary_Contact__r.phone from Opportunity
                where id = :ApexPages.currentPage().getParameters().get('id')];
        return opp;
    }
    public getLegs() {
        legs = [select Departure__c, Arrival__c from Leg__c
                where Opportunity__c = :ApexPages.currentPage().getParameters().get('id')];
    }

}

I can't get it to compile! I keep getting

Error: myController Compile Error: Invalid constructor name: getLegs at line 12 column 12

What am I doing wrong, and how can this be solved?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

原谅我要高飞 2024-12-05 00:36:11

你有一个函数 public getLegs() 因为它没有指定返回类型,它认为它是一个构造函数,但名称错误,所以错误有点误导,实际问题是getLegs() 函数没有说明其返回类型是什么,它应该是 public List; getLegs()(并且您需要添加一个返回腿

you have a function public getLegs() because it doesn't specify a return type, it thinks its a constructor, but has the wrong name, so the error is somewhat misleading, the actual problem is that the getLegs() function doesn't say what its return type is, it should e public List<Leg__c> getLegs() (and you need to add a return legs)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文