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

Class Salesforce-无效的构造函数名称错误,class,constructor,controller,salesforce,apex-code,Class,Constructor,Controller,Salesforce,Apex Code,我正在构建一个控制器,在Visualforce页面上显示来自自定义对象的数据。这是我的班级: public class myController { Opportunity opp; list<Leg__c> legs; public Opportunity getOpp() { if(opp == null) opp = [select name, Primary_Contact__r.name, Primary_

我正在构建一个控制器,在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{
机会opp;
列出腿;
公共机会{
if(opp==null)
opp=[从Opportunity中选择姓名、主要联系人姓名、主要联系人电子邮件、主要联系人电话
其中id=:ApexPages.currentPage().getParameters().get('id');
返回opp;
}
公营机构{
支腿=[从支腿c中选择出发支腿c、到达支腿c
其中Opportunity_uuC=:ApexPages.currentPage().getParameters().get('id');
}
}
我无法编译它!我一直在

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


我做错了什么,如何解决这个问题?

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

完美!我没有意识到我实际上应该使用一个函数(对apex来说非常新,哈哈)