Salesforce - 构造函数名称无效错误
我正在构建一个控制器来显示 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你有一个函数
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 epublic List<Leg__c> getLegs()
(and you need to add areturn legs
)