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
Irene SlessIrene Sless 

Constructor not define in controller test class

I've looked at several other posts in the forum regarding this, but none seem to have my problem. My VF page does not use an sObject, so I don't know what to do next, and would appreciate any help please.
I get the following error:
Constructor not defined: [CallCyclePrintController].<Constructor>(ApexPages.StandardController)

My VF form:
<apex:page showHeader="false" sidebar="false" controller="CallCyclePrintController">

    <head>
        <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
        <script>

            $j = jQuery.noConflict();
            
            $j(document).ready(function() {           
                window.print();
            });

        </script>

        <style>

            body {
                margin: 10px;
            }
            .title {
                padding: 5px 0;
            }

            .title h1 {
                font-size: 20px;
            }

            .account {
                padding: 5px;
                border-top: solid 1px #000;
                margin-top: 3px;
            }

            .clearBoth {
                clear: both;
            }
            
            table {
                width: 100%;
            }
            table, th, td{
                border: 1px solid #ccc;
                border-collapse: collapse;
            }
            th, td{
                padding: 5px;
                font-size: 9px;
            }

            @page {
                @bottom-right {
                    content: counter(page) " of " counter(pages);
                }
            }

        </style>
    </head>

    <div class="title">
        <h1>Call Cycle Schedule For: {!CallCycleModel.CallCycle.SalesPerson__r.Name} [Date: {!CallCycleDate}]</h1>
    </div>

        <table>
            <thead>
                <tr>
                    <th>CRM</th>                  
                    <th>Name</th>                  
                    <th>Phone</th>                  
                    <th>Mobile</th>                  
                    <th>Title</th>                  
                    <th>Department</th>                  
                    <th>Category</th>                  
                </tr>
            </thead>
            <tbody>
                <apex:repeat value="{!CallCycleModel.CallCycleActivities}" var="activity">
      
                <tr>
                    <td colspan="7" class="account">
                        <h2>{!activity.CallCycleActivity.Account__r.AccredoID__c} - {!activity.CallCycleActivity.Account__r.Name}</h2>
                    </td>
                </tr>
                <apex:repeat value="{!activity.CallCycleActivityContacts}" var="contact">
                    <tr>        
                        <td class="">
                            {!contact.Contact__r.AccredoCRMGroup__c}
                        </td>
            
                        <td class="">
                            {!contact.Contact__r.Name}
                        </td>
            
                        <td class="">
                            {!contact.Contact__r.Phone}
                        </td>
                        <td class="">
                            <div>{!activity.CallCycleActivity.CallCycleCategory__c}</div>
                            <div><apex:outputField value="{!contact.Contact__r.LastMemoContent__c}"/></div>
                        </td>
                    </tr>          
                        <td class="">
                            <div>{!activity.CallCycleActivity.MeetingTime__c}</div>
                        </td>
    
                </apex:repeat>
                </apex:repeat>
            </tbody>
        </table>

</apex:page>

My Controller class:
public with sharing class CallCyclePrintController {
    
    string CallCycleId { get; set; }
    public CallCycleModel CallCycleModel { get; set; }
    
    public string CallCycleDate {
        get {
            DateTime d = DateTime.newInstance(CallCycleModel.CallCycle.Date__c.Year(),
                                              CallCycleModel.CallCycle.Date__c.Month(),
                                              CallCycleModel.CallCycle.Date__c.Day());
            
            return d.format('dd/MM/yyyy');
        }
    }
    
    //-----------------------------------------------------------------------------------------
    public CallCyclePrintController() {
        CallCycleId = ApexPages.currentPage().getParameters().get('id');
        CallCycleModel = new CallCycleModel();
        system.debug('##CCPC enter - CCId: ' + CallCycleId);        
        
        //set the call cycle
        CallCycleModel.CallCycle = [Select Id, Date__c, Name, SalesPerson__r.Name
                                    From CallCycle__c 
                                    Where Id = :CallCycleId];
        system.debug('##CCPC CallCycleModel: ' + CallCycleModel);        
        
        //get the activities
        List<CallCycleActivity__c> ccas = [Select Id, Name, Account__r.AccredoID__c, Account__r.Name, Account__r.AccountNumber, Account__r.OtherPartyCode__c,
                                           Account__r.ShippingStreet, Account__r.ShippingCity, Account__r.AccountGroup__c, Account__r.Account_Group_Description__c, 
                                           Account__r.LastMemoContent__c, Account__r.Project_Team_Leader__r.Name,
                                           CallCycleCategory__c, ActivityID__c, EventDateTime__c, JointVisit__c, 
                                           Client_EndUser__c, Client_EndUser__r.MailingStreet, Client_EndUser__r.MailingCity
                                           From CallCycleActivity__c
                                           Where CallCycle__c = :CallCycleModel.CallCycle.Id
                                           Order By EventDateTime__c];
        system.debug('##CCPC ccas: ' + ccas);        
        
        Map<Id, Event> activities = GetEvents(ccas);
        system.debug('##CCPC activities : ' + activities );        
        
        Map<Id, Contact> contacts = GetEventContacts(activities);
        system.debug('##CCPC contacts : ' + contacts );        
        
        Map<Id, Memo__c> alarms = GetAlarms(ccas);
        system.debug('##CCPC alarms: ' + alarms );        
        
        for(CallCycleActivity__c c : ccas){
            CallCycleActivityModel ccaModel = new CallCycleActivityModel();
            ccaModel.CallCycleActivity = c;
            
            system.debug('##CCPC ccaModel.CallCycleActivity: ' + ccaModel.CallCycleActivity);        
            //get the event and contact sObjects
            Event e = activities.get(c.ActivityID__c);
            ccaModel.CallCycleEvent = e;
            if(e != null){
                Contact eventContact = contacts.get(e.Id);
                ccaModel.CallCycleEventContact = eventContact;
                system.debug('##CCPC eventContact: ' + eventContact);  
            }
            Memo__c acctAlarm = alarms.get(c.Account__c);
            system.debug('##CCPC acctAlarm: ' + acctAlarm);        
            //            ccaModel.CallCycleEventActAlarm = acctAlarm;
            
            //get the contacts
            List<CallCycleActivityContact__c> ccacs = [Select Id, isSelected__c,Contact__r.AccredoCRMGroup__c, Contact__r.Name, Contact__r.Phone, 
                                                       Contact__r.MobilePhone, Contact__r.AccredoAlarms__c, Contact__r.Department, 
                                                       Contact__r.Title , Contact__r.LastMemoContent__c
                                                       From CallCycleActivityContact__c
                                                       Where CallCycleActivity__c = :c.Id
                                                       And isSelected__c = true];
            
            system.debug('##CCPC ccacs: ' + ccacs);        
            if(ccacs == null || ccacs.size() == 0){
                continue;
            }
            
            for(CallCycleActivityContact__c ccac : ccacs){
                CallCycleActivityContactModel ccacModel = new CallCycleActivityContactModel();
                ccacModel.CallCycleActivityContact = ccac;
                
                system.debug('##CCPC ccac: ' + ccac);        
                ccaModel.CallCycleActivityContacts.add(ccac);
            }
            
            CallCycleModel.CallCycleActivities.add(ccaModel);
            system.debug('##CCPC ccaModel: ' + ccaModel);        
        }
        
    }
    
    
    //-----------------------------------------------------------------------------------------
    
    public Map<Id, Event> GetEvents(List<CallCycleActivity__c> ccas){
        List<string> activityIds = new List<string>();
        
        for(CallCycleActivity__c c : ccas){
            if(c.ActivityID__c != null){
                activityIds.add(c.ActivityID__c);
            }
            
        }
        
        system.debug('##CCPC ccas: ' + ccas);        
        Map<Id, Event> events = new Map<Id, Event>([Select Id, ActivityDate, StartDateTime, Description, EventCategory__c,
                                                    Who.Name, Owner.Name
                                                    From Event Where Id In :activityIds]);
        
        return events;
    }
    
    //-----------------------------------------------------------------------------------------
    
    public Map<Id, Contact> GetEventContacts(Map<Id, Event> events){
        List<Id> contactIds = new List<Id>();
        
        for(Event e : events.values()){
            if(e.WhoId != null){
                contactIds.add(e.WhoId);
            }
            
        }
        
        system.debug('##CCPC events: ' + events);        
        Map<Id, Contact> contacts = new Map<Id, Contact>([Select Id, Name, Phone, MobilePhone, Department, Title,
                                                          AccredoMailoutCode__c, LastMemoContent__c
                                                          From Contact Where Id In :contactIds]); 
        
        //now create a map between events and contacts
        Map<Id, Contact> eventContacts = new Map<Id, Contact>();
        
        for(Event e : events.values()){
            if(e.WhoId != null){
                Contact c = contacts.get(e.WhoId);
                
                eventContacts.put(e.Id, c);
            }
            
        }
        
        return eventContacts;
    }
    
    
    //-----------------------------------------------------------------------------------------
    
    public Map<Id, Memo__c> GetAlarms(List<CallCycleActivity__c> ccas){
        List<string> acctIds = new List<string>();
        
        for(CallCycleActivity__c c : ccas){
            if(c.Account__c != null){
                acctIds.add(c.Account__c);
            }
            
        }
        
        system.debug('##CCPC ccas: ' + ccas);        
        Map<Id, Memo__c> memos = new Map<Id, Memo__c>([Select Id, Account__c, Subject__c, Memo_Notes__c, About_What__c
                                                       From Memo__c Where Account__c In :acctIds and Active__c=true and Type__c='Instruction']);
        
        return memos;
    }

    //-----------------------------------------------------------------------------------------
    
    /*///////
    //Models
    ///////*/
    public class CallCycleModel {
        public CallCycle__c CallCycle { get; set; }
        
        public List<CallCycleActivityModel> CallCycleActivities { get; set; }
        public CallCycleModel(){
            CallCycleActivities = new List<CallCycleActivityModel>();
            system.debug('##CCPC CallCycleModel:CallCycleActivities: ' + CallCycleActivities);        
        }
    }
    
    //-----------------------------------------------------------------------------------------
    public class CallCycleActivityModel {
        public CallCycleActivity__c CallCycleActivity { get; set; }
        public Event CallCycleEvent { get; set; }
        
        public string CallCycleEventTime {
            get{
                
                if(CallCycleEvent != null && CallCycleEvent.StartDateTime != null){
                    return CallCycleEvent.StartDateTime.format('HH:mm');
                }
                return '00:00';
            }
        }
        
        public Contact CallCycleEventContact { get; set; }
        
        public List<CallCycleActivityContact__c> CallCycleActivityContacts { get; set; }
        public List<CallCycleActivityAlarm__c> CallCycleActivityAlarms { get; set; }
        
        public CallCycleActivityModel(){
            CallCycleActivityContacts = new List<CallCycleActivityContact__c>();
            CallCycleActivityAlarms = new List<CallCycleActivityAlarm__c>();
            system.debug('##CCPC line 190 CallCycleActivityModel:CallCycleActivityContacts:' + CallCycleActivityContacts );        
        }
        
    }
    
    //-----------------------------------------------------------------------------------------
    public class CallCycleActivityContactModel {
        public CallCycleActivityContact__c CallCycleActivityContact { get; set; }
        
        public string Alarm {
            get {
                string a = CallCycleActivityContact.Contact__r.AccredoAlarms__c;
                system.debug('##CCPC line 202');        
                return a;
            }
        }
    }
    
    //-----------------------------------------------------------------------------------------
    public class CallCycleActivityAlarmModel {
        public CallCycleActivityAlarm__c CallCycleActivityAlarm { get; set; }
    }
      
    
}

My test class:
@isTest
private class TestCallCyclePrintController {

    //-----------------------------------------------------------------------------------------
    @isTest static void TestCallCyclePrintController() {

        PageReference pageRef = Page.CallCyclePrint;
        Test.setCurrentPage(pageRef);

        User u = [Select Id From User Where Id = :UserInfo.getUserId()];
        system.debug('@@@ u: ' + u);
                
		Id recType = Schema.SObjectType.Memo__c.getRecordTypeInfosByName().get('Account').getRecordTypeId();

        Account a = new Account();
        a.Name = 'Test';
        a.OtherPartyCode__c = '40';
        a.Owner = u;
        a.ShippingStreet = 'Street';
        a.AccountNumber = '040abcde';
        
        insert a;
        system.debug('@@@ a.Owner: ' + a.Owner);
        
        Contact c = new Contact();
        c.LastName = 'Test';
        c.AccountId = a.Id;
        c.AccredoCRMGroup__c = '001';
        c.CallCycleFrequency__c = '3 monthly';
        c.ConfirmAppointment__c = true;
        insert c;

        Contact c2 = new Contact();
        c2.AccountId = a.Id;
        c2.LastName = 'test';
        c2.AccredoCRMGroup__c = '002';
        c2.ConfirmAppointment__c = false;
        
        insert c2;
        
        CallCycle__c callCycle = new CallCycle__c();
        callCycle.Date__c = Date.today();
        callCycle.CycleStart__c = 10;
        callCycle.CycleEnd__c = 50;
        callCycle.SalesPerson__c = u.Id;

        insert callCycle;
        ApexPages.currentPage().getParameters().put('id', callCycle.Id);
        
        CallCycleActivity__c cca = new CallCycleActivity__c();
        cca.Account__c = a.Id;
        cca.CallCycle__c = callCycle.id;
        cca.EventDate__c = date.parse('05/11/2015');
		cca.CallCycleCategory__c = 'Sales Drop In';
        
        insert cca;     
       
//        ApexPages.StandardController sc = new ApexPages.standardController(callCycle);
        CallCyclePrintController controller = new CallCyclePrintController(new ApexPages.standardController(callCycle));
        

    }

}

 
Abhishek BansalAbhishek Bansal
Hi Irene,

The error is coming surely from test class beacuse you have defined wrong constructor in it.
Your controller class is using just a simple constructor but you are initializing your test class with a parameterized constructor so it is throwing error as constructor is not defined.
I have updated your test class, please use the below test class :
@isTest
private class TestCallCyclePrintController {

    //-----------------------------------------------------------------------------------------
    @isTest static void TestCallCyclePrintController() {

        PageReference pageRef = Page.CallCyclePrint;
        Test.setCurrentPage(pageRef);

        User u = [Select Id From User Where Id = :UserInfo.getUserId()];
        system.debug('@@@ u: ' + u);
                
		Id recType = Schema.SObjectType.Memo__c.getRecordTypeInfosByName().get('Account').getRecordTypeId();

        Account a = new Account();
        a.Name = 'Test';
        a.OtherPartyCode__c = '40';
        a.Owner = u;
        a.ShippingStreet = 'Street';
        a.AccountNumber = '040abcde';
        
        insert a;
        system.debug('@@@ a.Owner: ' + a.Owner);
        
        Contact c = new Contact();
        c.LastName = 'Test';
        c.AccountId = a.Id;
        c.AccredoCRMGroup__c = '001';
        c.CallCycleFrequency__c = '3 monthly';
        c.ConfirmAppointment__c = true;
        insert c;

        Contact c2 = new Contact();
        c2.AccountId = a.Id;
        c2.LastName = 'test';
        c2.AccredoCRMGroup__c = '002';
        c2.ConfirmAppointment__c = false;
        
        insert c2;
        
        CallCycle__c callCycle = new CallCycle__c();
        callCycle.Date__c = Date.today();
        callCycle.CycleStart__c = 10;
        callCycle.CycleEnd__c = 50;
        callCycle.SalesPerson__c = u.Id;

        insert callCycle;
        ApexPages.currentPage().getParameters().put('id', callCycle.Id);
        
        CallCycleActivity__c cca = new CallCycleActivity__c();
        cca.Account__c = a.Id;
        cca.CallCycle__c = callCycle.id;
        cca.EventDate__c = date.parse('05/11/2015');
		cca.CallCycleCategory__c = 'Sales Drop In';
        
        insert cca;     
       
//        ApexPages.StandardController sc = new ApexPages.standardController(callCycle);
        CallCyclePrintController controller = new CallCyclePrintController();
        

    }

}
Let me know if you still have any issue in it.

Thanks,
Abhishek
Amit Chaudhary 8Amit Chaudhary 8
Please check below post for Test classes. I hope that will help you
http://amitsalesforce.blogspot.in/search/label/Test%20Class
http://amitsalesforce.blogspot.in/2015/06/best-practice-for-test-classes-sample.html

Sample Test Class for Standard Controller.
Test.StartTest(); 
  ApexPages.StandardController sc = new ApexPages.StandardController(testAccount);
  myControllerExtension testAccPlan = new myControllerExtension(sc);

  PageReference pageRef = Page.AccountPlan; // Add your VF page Name here
  pageRef.getParameters().put('id', String.valueOf(testAccount.Id));
  Test.setCurrentPage(pageRef);

  //testAccPlan.save(); call all your function here
 Test.StopTest();
Sample Test Class for Controller class
Test.StartTest(); 

  PageReference pageRef = Page.AccountPlan; // Add your VF page Name here
  pageRef.getParameters().put('id', String.valueOf(testAccount.Id));
  Test.setCurrentPage(pageRef);

  myController testAccPlan = new myController();
  
  //testAccPlan.save(); call all your function here
 Test.StopTest();

As as per above example . In case on Standard controller you need to pass StandardController object in custructor but in case of controller you can pass it without any StandardController object.

Please try below code.
@isTest
private class TestCallCyclePrintController {
    @isTest static void TestCallCyclePrintController() 
	{
        PageReference pageRef = Page.CallCyclePrint;
        Test.setCurrentPage(pageRef);

        User u = [Select Id From User Where Id = :UserInfo.getUserId()];
        system.debug('@@@ u: ' + u);
                
		Id recType = Schema.SObjectType.Memo__c.getRecordTypeInfosByName().get('Account').getRecordTypeId();

        Account a = new Account();
        a.Name = 'Test';
        a.OtherPartyCode__c = '40';
        a.Owner = u;
        a.ShippingStreet = 'Street';
        a.AccountNumber = '040abcde';
        
        insert a;
        system.debug('@@@ a.Owner: ' + a.Owner);
        
        Contact c = new Contact();
        c.LastName = 'Test';
        c.AccountId = a.Id;
        c.AccredoCRMGroup__c = '001';
        c.CallCycleFrequency__c = '3 monthly';
        c.ConfirmAppointment__c = true;
        insert c;

        Contact c2 = new Contact();
        c2.AccountId = a.Id;
        c2.LastName = 'test';
        c2.AccredoCRMGroup__c = '002';
        c2.ConfirmAppointment__c = false;
        
        insert c2;
        
        CallCycle__c callCycle = new CallCycle__c();
        callCycle.Date__c = Date.today();
        callCycle.CycleStart__c = 10;
        callCycle.CycleEnd__c = 50;
        callCycle.SalesPerson__c = u.Id;

        insert callCycle;
        ApexPages.currentPage().getParameters().put('id', callCycle.Id);
        
        CallCycleActivity__c cca = new CallCycleActivity__c();
        cca.Account__c = a.Id;
        cca.CallCycle__c = callCycle.id;
        cca.EventDate__c = date.parse('05/11/2015');
		cca.CallCycleCategory__c = 'Sales Drop In';
        
        insert cca;     
       
        CallCyclePrintController controller = new CallCyclePrintController();
        

    }

}
Please follow below salesforce Best Practice for Test Classes :-

1. Test class must start with @isTest annotation if class class version is more than 25
2. Test environment support @testVisible , @testSetUp as well
3. Unit test is to test particular piece of code working properly or not .
4. Unit test method takes no argument ,commit no data to database ,send no email ,flagged with testMethod keyword .
5. To deploy to production at-least 75% code coverage is required
6. System.debug statement are not counted as a part of apex code limit.
7. Test method and test classes are not counted as a part of code limit
9. We should not focus on the  percentage of code coverage ,we should make sure that every use case should covered including positive, negative,bulk and single record .
Single Action -To verify that the the single record produces the correct an expected result .
Bulk action -Any apex record trigger ,class or extension must be invoked for 1-200 records .
Positive behavior : Test every expected behavior occurs through every expected permutation , i,e user filled out every correctly data and not go past the limit .
Negative Testcase :-Not to add future date , Not to specify negative amount.
Restricted User :-Test whether a user with restricted access used in your code .10. Test class should be annotated with @isTest .
11 . @isTest annotation with test method  is equivalent to testMethod keyword .
12. Test method should static and no void return type .
13. Test class and method default access is private ,no matter to add access specifier .
14. classes with @isTest annotation can't be a interface or enum .
15. Test method code can't be invoked by non test request .
16. Stating with salesforce API 28.0 test method can not reside inside non test classes .
17. @Testvisible annotation to make visible private methods inside test classes.
18. Test method can not be used to test web-service call out . Please use call out mock .
19. You can't  send email from test method.
20.User, profile, organization, AsyncApexjob, Corntrigger, RecordType, ApexClass, ApexComponent ,ApexPage we can access without (seeAllData=true) .
21. SeeAllData=true will not work for API 23 version eailer .
22. Accessing static resource test records in test class e,g List<Account> accList=Test.loadData(Account,SobjectType,'ResourceName').
23. Create TestFactory class with @isTest annotation to exclude from organization code size limit .
24. @testSetup to create test records once in a method  and use in every test method in the test class .
25. We can run unit test by using Salesforce Standard UI,Force.com IDE ,Console ,API.
26. Maximum number of test classes run per 24 hour of period is  not grater of 500 or 10 multiplication of test classes of your organization.
27. As apex runs in system mode so the permission and record sharing are not taken into account . So we need to use system.runAs to enforce record sharing .
28. System.runAs will not enforce user permission or field level permission .
29. Every test to runAs count against the total number of DML issued in the process .


Please let us know if this post will help you