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
Terry411Terry411 

Unknown Constructor

Gosh guys/gals... sometimes I just don't get it...  I've seen scores of other post with this same issues and feel like I've tried most of them and still can't resolve this error.  I must be missing something but I'm new enough to not know what it is.  Thanks for any help.

 

error: Unknown constructor 'conQuickEmail.conQuickEmail(ApexPages.StandardController controller)'

 

Here's my VF page's controller line:

<apex:page standardController="lead" extensions="conQuickEmail" id="page" tabStyle="lead">

 

Here's my latest try for the controller:

public with sharing class conQuickEmail {

private final ApexPages.StandardSetController stdController;

public conQuickEmail(ApexPages.StandardSetController controller) {
	this.stdController = (Lead)stdcontroller.getRecord();              //  <-- this is line 23

// rest of the code
}

 

Here's my test class which gives me this error:  error: Variable does not exist: ApexPages.StandardSetController

private static testmethod void  quickEmailTests() {
	Lead l = [select id from Lead where EmailBouncedDate = null and email != null limit 1];
	PageReference testPage = Page.Quick_Email;
	testPage.getParameters().put('rec',l.id);
	testPage.getParameters().put('retURL','/home/home.jsp');
	Test.setCurrentPage(testPage);
	
	conQuickEmail controller = new conQuickEmail(ApexPages.StandardSetController(l));
	controller.send();
  
	Lead l2 = [select id from Lead where EmailBouncedDate = null and email != null limit 1];
	testPage = Page.Quick_Email;
	testPage.getParameters().put('rec',l2.id);
	testPage.getParameters().put('retURL','/home/home.jsp');
	Test.setCurrentPage(testPage);
	controller = new conQuickEmail(ApexPages.StandardSetController(l));
	controller.send();
	controller.cancel();

 

 

aballardaballard

You need to actually create a standard controller object to pass to your extension controller constructor:

 

Something like

 

conQuickEmail controller = new conQuickEmail(new ApexPages.StandardSetController(l))



Terry411Terry411

I made the change you recommended.  (see updated code above).  I now have the following errors:

 

error: Illegal assignment from SOBJECT:Lead to ApexPages.StandardSetController   line 23

 

error: Unknown constructor 'conQuickEmail.conQuickEmail(ApexPages.StandardController controller)' Quick_Email.page line 0

 

I really appreciate any help.  Been trying to correct this for hours.  

Shashikant SharmaShashikant Sharma

Use this it should work for you

 

private static testmethod void  quickEmailTests() {
    
    List<Lead> l = [select id from Lead where EmailBouncedDate = null and email != null limit 1];
    PageReference testPage = Page.Quick_Email;
    testPage.getParameters().put('rec',l.id);
    testPage.getParameters().put('retURL','/home/home.jsp');
    Test.setCurrentPage(testPage);
    
    conQuickEmail controller = new conQuickEmail(new ApexPages.StandardSetController(l));
    
    controller.send();
  
    Lead l2 = [select id from Lead where EmailBouncedDate = null and email != null limit 1];
    testPage = Page.Quick_Email;
    testPage.getParameters().put('rec',l2.id);
    testPage.getParameters().put('retURL','/home/home.jsp');
    Test.setCurrentPage(testPage);
    controller = new conQuickEmail(ApexPages.StandardSetController(l));
    controller.send();
    controller.cancel();
    }

 The mistake was that StandardSetController should always take a list of object. In your test emthod you were passing only object instance of lead. I updated it to pass list of lead.

I hope it will  help you.

pat!pat!

I don't know yet your requirements but please try these suggestions :)

 

Change your constructor to ApexPages.StandardController instead of ApexPages.StandardSetController.

 

public conQuickEmail(ApexPages.StandardController controller) {
	this.stdController = (Lead)stdcontroller.getRecord();

 

Next, create a variable for ApexPages.StandardController that will hold the value that is passed in the constructor

 

private ApexPages.StandardController stdController;

 

If you need to get a record for a lead record.. you should create a variable container for it.

 

so your final code should look like this:

 

private Lead lead;
private ApexPages.StandardController controller;

public conQuickEmail(ApexPages.StandardController stdController){
   controller = stdController;
   this.lead = (Lead)controller.getRecord();
}

 I just code it here and haven't tested it in a compiler.. maybe a little error might come up but I think you can handle it now. Also, I don't know why you need an ApexPages.StandardSetController for. I'm new to Salesforce development as well so I don't know much about such syntax yet haha.

 

error: Unknown constructor 'conQuickEmail.conQuickEmail(ApexPages.StandardCon​troller controller)' <-- based on this error, the final code that I suggested should work. I didn't look into your test method any further for I haven't made at least one yet hahaha :)

 

Hope this could help you.

 

Best Regards,

Pat

Terry411Terry411

@Pat,

 

Thanks for your response.  So far none of the suggestions have worked.  Maybe I'm simply going down the wrong path.  What I have is a VF page that I'm trying to call with a custom List Button from the Lead tab.  The basic issue I was originally trying to solve was the issue of my VF Page not displaying as an Option in the New custom Button or Link page.  When looking for solutions for this everything was pointing to syntax using a Standard Controller and the ApexPages.Standard (Set) Controller format when calling the controller.  Technially, I don't believe I even need the standard controller in my code unless that is the key to setting up the custom button.

 

The actual code is very similar to the standard code Salesforce used for their Mail Merge.  The unique part of my code is that it automatically loads a specific email template. There's nothing spectacular going on.  Does that help?

Shashikant SharmaShashikant Sharma

Did you tried this

 

private static testmethod void  quickEmailTests() {
    
    List<Lead> l = [select id from Lead where EmailBouncedDate = null and email != null limit 1];
    PageReference testPage = Page.Quick_Email;
    testPage.getParameters().put('rec',l.id);
    testPage.getParameters().put('retURL','/home/home.jsp');
    Test.setCurrentPage(testPage);
    
    conQuickEmail controller = new conQuickEmail(new ApexPages.StandardSetController(l));
    
    controller.send();
  
    Lead l2 = [select id from Lead where EmailBouncedDate = null and email != null limit 1];
    testPage = Page.Quick_Email;
    testPage.getParameters().put('rec',l2.id);
    testPage.getParameters().put('retURL','/home/home.jsp');
    Test.setCurrentPage(testPage);
    controller = new conQuickEmail(ApexPages.StandardSetController(l));
    controller.send();
    controller.cancel();
    }

 Please let  me know if any issue comes. I think this should work.

Terry411Terry411

I think my issue is a data problem... I just realized the dev environment I'm in doesn't have valid data so the tests are returning no records.  Sorry everyone.  I'll get that corrected and hopefully the problems will be eliminated as well.  I'm getting good as not seeing the tress for the forest.