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

Constructor Not Defined error in test class

I am trying to instantiate my controller in my test class but I had to do the controller class slightly differently then others that I've done in the past and so I can't figure out how to get it define in the test class.


My controllerclass  says this for the page controller

private Id demoId;

    private ApexPages.StandardController controller;

    public DemoContactEntryExtension(ApexPages.StandardController controller) {
        this.controller = controller;

        // get the id of the demo
        demoId = controller.getId();


my test class says this:


//Create Test Data

Account a=new Account(Name='Test Account');
    insert a;
Contact c = new Contact(FirstName='John',LastName='Doe',;
    insert c;
Opportunity o = new Opportunity(Name='Test Opportunity',, stagename='Confirmed Teaching/Class Schedule',Probability=0.95,;
    insert o;      
OpportunityContactRole ocr = new OpportunityContactRole (Opportunityid =,, role='Decision Maker', isPrimary=True) ;     
    insert ocr;  
Demo__c demo = new Demo__c (, Name='Test Demo');
    insert demo;
Demo_Opportunity__c doc = new Demo_Opportunity__c (,;
    insert doc;
Demo_Contact__c dcc = new Demo_Contact__c (,;
    insert dcc;

        //  test DemoContactEntry
           // load the page             
        PageReference pageRef = Page.Demo_Contact_Entry;
    // load the extension
        DemoContactEntryExtension dCEE = new DemoContactEntryExtension(new ApexPages.StandardController(dcc.demo__c));

If anyone knows how I can change this to instantiate the controller that would be great.








DemoContactEntryExtension dCEE = new DemoContactEntryExtension(new ApexPages.StandardController(dcc.demo__c));


Replace above line with below.


DemoContactEntryExtension dCEE = new DemoContactEntryExtension(new ApexPages.StandardController(dcc));



Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.

Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator
My Blog:-