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
Waqar Hussain SFWaqar Hussain SF 

I got this error when i save my test class. Constructor not defined: [recordExt].<Constructor>()

here is my class..
@IsTest
public class TestrecordExt{
   
    static testMethod void TestEmp(){
   
        //test.startTest();
        List<employee__c> eList = new List<employee__c>();
        employee__c e = new employee__c();
        e.Name = 'test';
        e.Last_Name__c = 'test';
        e.Join_Date__c = Date.Today();
        e.City__c = 'test city';
        e.Phone__c = '123456';
        eList.add(e);
   
       
        e = new employee__c();
        e.Name = 'employee Name';
        e.Last_Name__c = 'emp Last Name';
        e.Join_Date__c = Date.Today();
        e.City__c = 'test city';
        e.Phone__c = '123456';
        eList.add(e);
       
        insert eList;
       
        recordExt r = new recordExt();
        r.saveEmp();
   
        //test.stopTest();
    }

}
Best Answer chosen by Waqar Hussain SF
Anoop yadavAnoop yadav
Hi,

You did not define the default Constructor in your controller.
Create a Constructor in your controller like below.

public recordExt(){

}

All Answers

Anoop yadavAnoop yadav
Hi,

You did not define the default Constructor in your controller.
Create a Constructor in your controller like below.

public recordExt(){

}
This was selected as the best answer
Grazitti TeamGrazitti Team
Hi Waqar,

You have used the same instance name for insertion in the custom object. The instance name should be different while doing insertion in the object.

I have made some changes in the code. Please see below for details.

@IsTest
public class TestrecordExt{
   
    static testMethod void TestEmp(){
   
        //test.startTest();
        List<employee__c> eList = new List<employee__c>();
        employee__c e = new employee__c();
        e.Name = 'test';
        e.Last_Name__c = 'test';
        e.Join_Date__c = Date.Today();
        e.City__c = 'test city';
        e.Phone__c = '123456';
        eList.add(e);
   
       
        employee__c e1 = new employee__c();
        e1.Name = 'employee Name';
        e1.Last_Name__c = 'emp Last Name';
        e1.Join_Date__c = Date.Today();
        e1.City__c = 'test city';
        e1.Phone__c = '123456';
        eList.add(e1);
       
        insert eList;
       
        recordExt r = new recordExt();
        r.saveEmp();
   
        //test.stopTest();
    }

}
Please mark as best answer if it helps you.

Regards,
Grazitti Team,
www.grazitti.com