Salesforce - Invalid constructor name error
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')];
}
}开发者_Go百科
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?
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
)
精彩评论