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
kathybbkathybb 

Problem with Test Code for Controller Extension for Custom object

I've run into a problem with my Test code for a Controller extension.  The error message I get is: Constructor not defined: [Test_Line_Edit_Extension].<Constructor>(ApexPages.StandardController).  I need to get this fixed so I can deploy it to production to enable me to get rid of code that somehow made it into Production without accompanying test code.  Here is my test code:
@istest
public class Test_Line_Edit_Extension 
{
	public static testmethod void Test_Line_Edit_Extension()
	{
        Order_Line_Item__c initLI = new Order_Line_Item__c();
        ApexPages.StandardController sc = new ApexPages.standardController(initLI);
        Test_Line_Edit_Extension ext1 = new Test_Line_Edit_Extension(sc);
        ext1.getRecord(initLI);
        
       	Product2 myProduct = [select id, ProductCode, Family, Description
    	from Product2 where productCode = 'K PSIP MSL' Limit 1];
		Order__c myOrder = new Order__c();
		List<Order__c>OrdersList = new List<Order__c>();
		List<Order_Line_Item__c> LIList = new List<Order_Line_Item__c>();
		Account testAccount = new Account(Name = 'KBB Test Account');
		insert testAccount;
        if(testAccount.id != null)
        {
			myOrder = new Order__c(Customer_Account__c = testAccount.id);
		
			for(integer x = 1; x< 10;x++)
			{
			Order_Line_Item__c myLineItem = new Order_Line_Item__c(Name = myProduct.productCode + x, Price_per_unit__c = x,
            Quantity__c = 3, Year_of_Contract__c = 2,Type_of_Sale__c = 'Renewal',Order_Number__c = myOrder.id);
			system.assertEquals(myProduct.name, 'K PSIP MSL');
			system.assertEquals(myProduct.productCode, myLineItem.Product__c);
            }
        }
    }
	

}

Here is the code I'm trying to test:
public with sharing class LineEditExtension {

    private final Order_Line_Item__c m_ext {get;set;}
    public Order_Line_Item__c currentLine {get;set;}
    public ApexPages.StandardController m_con {get;set;}
    public ApexPages.StandardController m_Gstd {get;set;}
    public string m_currentLineId {get;set;}    
   
    public LineEditExtension(ApexPages.StandardController stdController){ 
        m_ext = (Order_Line_Item__c)stdController.getRecord();
    }
    
    public PageReference SaveAndNew(){
        ApexPages.StandardController m_Gstd = new ApexPages.StandardController(m_ext);
        PageReference OrderPage = m_Gstd.save(); 
        m_currentLineId=m_Gstd.getId(); 
        PageReference returnPage = new PageReference('/a07/e');
        return returnPage;
    }                                          
}

And here's the page:
<apex:page standardController="Order_Line_Item__c" extensions="LineEditExtension">
    <apex:sectionHeader title="{!$ObjectType.Order_Line_Item__c.label} Edit" subtitle="{!Order_Line_Item__c.name}"/>
    <apex:form >
    <apex:pageBlock title="{!$ObjectType.Order_Line_Item__c.label} Edit" mode="edit">
        <apex:pageBlockButtons >
            <apex:commandButton action="{!save}" value="Save"/>
            <apex:commandButton action="{!saveAndNew}" value="Save & New"/>
            <apex:commandButton action="{!cancel}" value="Cancel"/>
        </apex:pageBlockButtons>
        <apex:pageBlockSection showHeader="true" title="Information" columns="2">
            <apex:inputField required="true" value="{!Order_Line_Item__c.Product__c}"/>
            <apex:pageBlockSectionItem />
            <apex:pageBlockSectionItem />
            <apex:pageBlockSectionItem />
            <apex:inputField required="true" value="{!Order_Line_Item__c.Order_Number__c}"/>
            <apex:inputField value="{!Order_Line_Item__c.Length_of_Subscription__c}"/>
            <apex:pageBlockSectionItem />
            <apex:inputField value="{!Order_Line_Item__c.Year_of_Contract__c}"/>
        </apex:pageBlockSection>
        <apex:pageBlockSection showHeader="true" title="Details" columns="2">
            <apex:inputField value="{!Order_Line_Item__c.Quantity__c}"/>
            <apex:inputField value="{!Order_Line_Item__c.Type_of_Sale__c}"/>
            <apex:inputField value="{!Order_Line_Item__c.Price_per_Unit__c}"/>
            <apex:inputField value="{!Order_Line_Item__c.New_Money__c}"/>
            <apex:inputField value="{!Order_Line_Item__c.Renewal_Increase_money__c}"/>
        </apex:pageBlockSection>
        <apex:pageBlockSection showHeader="true" title="System Information" columns="2">
            <apex:pageBlockSectionItem />
            <apex:pageBlockSectionItem />
            <apex:inputField required="true" value="{!Order_Line_Item__c.Name}"/>
            <apex:pageBlockSectionItem />
        </apex:pageBlockSection>
    </apex:pageBlock>
    </apex:form>
</apex:page>

Any insight will save my sanity.
Thanks,
KathyBB
Best Answer chosen by kathybb
dev_sfdc1dev_sfdc1
Hi KathyBB,

You need to replace your testclass name to controller class name in test class..

Replace this line to controller class name :
Test_Line_Edit_Extension ext1 = new Test_Line_Edit_Extension(sc);

Put in test class as:
LineEditExtension ext1 = new LineEditExtension(sc);

Please Let me know if this helps you.

Thank You


All Answers

dev_sfdc1dev_sfdc1
Hi KathyBB,

You need to replace your testclass name to controller class name in test class..

Replace this line to controller class name :
Test_Line_Edit_Extension ext1 = new Test_Line_Edit_Extension(sc);

Put in test class as:
LineEditExtension ext1 = new LineEditExtension(sc);

Please Let me know if this helps you.

Thank You


This was selected as the best answer
kathybbkathybb
That solved my problem.  Thank you so much!