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
guyr1981guyr1981 

Error: Unknown constructor 'MyController.MyController(ApexPages.StandardSetController controller)'

Hi,

 

I have a custom controller called: MyController, I did 

Error: Unknown constructor 'MyController.MyController(ApexPages.StandardSetController controller)'.

 

On my controller code I have the following implementation of a simple constructor:

 

public class MyController {
    public Plan_Table__c table;
    public List <Table_Account__c> table_acc;
    public MyController() {
        table = null;
        table_acc = null;
    }

 

 

// some get and set APIs ....

...

...

...

}

 

Why do I keep getting this error when saving my tag file:

<apex:page standardStylesheets="false" sidebar="false" StandardController="Table_Account__c" Extensions="MyController" tabStyle="Account" recordSetVar="acc">

 

...

...

...

 

 

Thanks,

Guy

Best Answer chosen by Admin (Salesforce Developers) 
AvromAvrom

This isn't actually a custom controller, but rather a controller extension.

 

If you don't need standard controller functionality (and it looks like you don't, since you're not referring to it anywhere), the correct syntax for the page tag is

 

<apex:page standardStylesheets="false" sidebar="false" Controller= "MyController" tabStyle="Account">

 

If you're really trying to write a controller extention, then your extention needs to have a constructor that takes an argument of ApexPages.StandardSetController.

 

 public ApexPages.StandardSetController stdCntrlr {get; set;}

 public MyController(ApexPages.StandardSetController controller) {

        stdCntrlr = controller;
    }

All Answers

AvromAvrom

This isn't actually a custom controller, but rather a controller extension.

 

If you don't need standard controller functionality (and it looks like you don't, since you're not referring to it anywhere), the correct syntax for the page tag is

 

<apex:page standardStylesheets="false" sidebar="false" Controller= "MyController" tabStyle="Account">

 

If you're really trying to write a controller extention, then your extention needs to have a constructor that takes an argument of ApexPages.StandardSetController.

 

 public ApexPages.StandardSetController stdCntrlr {get; set;}

 public MyController(ApexPages.StandardSetController controller) {

        stdCntrlr = controller;
    }
This was selected as the best answer
ShawnFShawnF

Avrom

 

Hoping you can help with my issue. I am getting the same error message as the user above:

 

Error: Unknown constructor 'locatorDetails.locatorDetails(ApexPages.StandardController controller)'

 

I thought I had done everything as you said in your posted reply, but am still getting the "unknown constructor" error message.

 

Here is the code to my class:

 

public with sharing class locatorDetails {

// Query the db for the list of Suite__c records to use on the vf page and return a list
public ApexPages.StandardSetController suiteRecords{
get {
if(suiteRecords == null) {
suiteRecords = new ApexPages.StandardSetController(Database.getQueryLocator([Select s.id, s.Name, s.Status__c, s.Property__c from Suite__c s Where s.Status__c!= 'Leased' AND s.Property__c =:ApexPages.currentPage().getParameters().get('id')]));
}
return suiteRecords;
}
set;
}

// Create a list of type Suite__c and call the query method
public List<Suite__c> suiteRecords() {
return (List<Suite__c>) suiteRecords.getRecords();
}

// Query the db for the list of Spec_Sheet__c records to use on the vf page and return a list
public ApexPages.StandardSetController specRecords{
get {
if(specRecords == null) {
specRecords = new ApexPages.StandardSetController(Database.getQueryLocator([Select s.id, s.Name, s.Property__c, s.Suite__c from Spec_Sheet__c s Where (s.Suite__r.Status__c = 'Available') AND (s.Property__c =:ApexPages.currentPage().getParameters().get('id'))]));
}
return specRecords;
}
set;
}

// Create a list of type Spec_Sheet__c and call the query method
public List<Spec_Sheet__c> specRecords() {
return (List<Spec_Sheet__c>) specRecords.getRecords();
}
}

 

Here is my vf page tag:

 

<apex:page showHeader="false" sidebar="false" id="body" standardStylesheets="false" standardController="Property__c" extensions="locatorDetails">

 

In written english, what I am trying to accomplish is the following:

 

  • Have a details page for a specific Property__c record
  • For that property, show a list of related child Suite__c records where Status__c = 'Available'
  • For that property, show a list of related child Spec_Sheet__c records where Property__c = 'the id of the property being viewed'

 

Since I am still getting the "unknown constructor" error, I cannot determine where I correctly identify my Property__c object as the constructor for my extension.

 

I have referenced this page extensively to no avail:

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_pages_standardsetcontroller.htm

AvromAvrom

Hi Shawn,

 

I'm a bit confused...I don't see a constructor in your class at all.

 

A constructor looks a bit like a method, but it has no specified return type and the same name as the class. So it would look something like

 

 

public locatorDetails(ApexPages.StandardController controller) {
    ...
}

 

 

 

ShawnFShawnF

I believe I've added the missing constructor. Is this correct?

 

 

public with sharing class locatorDetails {
  
  private final Property__c prop;
  
  public locatorDetails(ApexPages.StandardController PropertyController) {
    this.prop = (Property__c)PropertyController.getRecord();
  }
  
  // Create a list of type Suite__c and call the query method
    public List<Suite__c> suiteRecords() {
         return (List<Suite__c>) suiteRecords.getRecords();
    }
    
  // Query the db for the list of Suite__c records to use on the vf page and return a list
    public ApexPages.StandardSetController suiteRecords{
      get {
            if(suiteRecords == null) {
                suiteRecords = new ApexPages.StandardSetController(Database.getQueryLocator([Select s.id, s.Name, s.Status__c, s.Property__c from Suite__c s Where s.Status__c!= 'Leased' AND s.Property__c =:ApexPages.currentPage().getParameters().get('id')]));
            }
            return suiteRecords;
        }
        set;
    }
    
    // Create a list of type Spec_Sheet__c and call the query method
    public List<Spec_Sheet__c> specRecords() {
         return (List<Spec_Sheet__c>) specRecords.getRecords();
    }    
    
  // Query the db for the list of Spec_Sheet__c records to use on the vf page and return a list   
    public ApexPages.StandardSetController specRecords{
      get {
            if(specRecords == null) {
                specRecords = new ApexPages.StandardSetController(Database.getQueryLocator([Select s.id, s.Name, s.Property__c, s.Suite__c from Spec_Sheet__c s Where (s.Suite__r.Status__c = 'Available') AND (s.Property__c =:ApexPages.currentPage().getParameters().get('id'))]));
            }
            return specRecords;
        }
        set;
    }              
}

 

 

sandeep reddy 37sandeep reddy 37
but Iam using controller and extenssion will i create constractor for class or will i pass parameter for constractor