July 27, 2010

Head Banger

Last night I spent around half an hour trying to work out why my constructor wasn't running in a Visualforce controller class. The code was your regular stuff, looking like this:

public with sharing class MyController 
{ 
    public    boolean mp_bMemberVar {get; set;} 
        
    public void MyController() 
    { 
        // stuff 
    } 
     
    public void Init() 
    { 
        // etc.. 
    } 
}

Can you spot the problem? Somehow in my haste I'd included the void keyword in there... so my constructor wasn't a constructor at all and as such, not being called when I expected it to. A warning on save would have been nice!