开发者

Salesforce - Invalid constructor name error

开发者 https://www.devze.com 2023-03-25 20:26 出处:网络
I\'m building a controller to show the data from a custom object on a Visualforce page. Here\'s my class:

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)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号