function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
MyGodItsColdMyGodItsCold 

'Invalid constructor name' for custom controller containing custom object

When I save my Controller, I get: Error: Compile Error: Invalid constructor name: getTeamContact at line 4 column 8
 
I created a custom object: TeamContact__c
In my Page editor, I have the following:
Code:
<apex:page controller="mailListController001" tabStyle="MailingList__c">
<apex:pageBlock title="Mail List Manager - For: {!$User.FirstName} {!$User.LastName}"/>
You have {!TeamContact.id}.
</apex:page>

 
In my Controller editor, I have the following:
Code:
public class mailListController001 {
 TeamContact__c TeamContact;
 public getTeamContact() {
  if (TeamContact == null) {
        TeamContact = [select id from TeamContact__c];
  }
  return TeamContact;
 }
}

 
The page is named ml001
 
I'm trying to KISS, but feeling a bit S
 
Thanks..
 
 
 
MyGodItsColdMyGodItsCold
Whoops, missing 'Public'  declaration on line 2 of Controller.
harsha287harsha287

It is not required to declare public in controller by default it takes private

hemantgarghemantgarg

You are missing the return type of your getter function, every function should have a return type otherwise it tries to inerpret as a constructor while the constructior name must be same as the class name, so it is complaining. Hope you get it.

harsha287harsha287
public teamcontact__C getTeamContact() {
  if (TeamContact == null) {
        TeamContact = [select id from TeamContact__c];
  }
  return TeamContact;
 }
}
just check it out it will work