2011-08-03 22 views
2

我正在構建控制器以顯示Visualforce頁面上自定義對象的數據。這是我的課程:Salesforce - 無效的構造函數名稱錯誤

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')]; 
    } 

} 

我無法得到它編譯!我不斷收到

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

我在做什麼錯,怎麼解決?

回答

6

您有一個函數public getLegs(),因爲它沒有指定返回類型,它認爲它是一個構造函數,但名稱錯誤,所以錯誤有點誤導,實際問題是getLegs()函數不會' t說什麼它的返回類型是,它應該是e public List<Leg__c> getLegs()(並且您需要添加return legs

+0

完美!我沒有意識到我實際上應該使用一個函數(非常新的頂點哈哈) –