I'm new to salesforce. I've written a vf page to display selected opportunities and massedit those records. Below is my controller class and test class. I'm getting an error "Constructor not defined" and my code coverage is 0%.. Can anybody please help me in getting this error fixed.

VF Page:

<apex:page standardController="Opportunity" 
     extensions="MassEditOppController"   recordSetVar="unused" sidebar="false">
     <apex:includeScript value="{!$Resource.UtilJS}" />
     <apex:form >

         <apex:pageBlock >
             <apex:pageMessages />

             <apex:pageBlockButtons >
                 <apex:commandButton value="Save" action="{!save}" onclick="if(!confirm('Do you want to update the below highlighted records?')){return false};"      />

             <apex:pageBlockTable value="{!objlist}" var="opp" id="table"  onRowClick="style.backgroundColor='yellow'"   >

                 <apex:column headerValue="Name"  >
                     <apex:inputField value="{!opp.name}"  />

                 <apex:column headerValue="Stage">
                     <apex:inputField value="{!opp.StageName}"  html-disabled="true" /> 

                 <apex:column headerValue="Expected Impact Date" >
                     <apex:inputField value="{!opp.Expected_Impact_Date__c}"    />

                 <apex:column headerValue="Cancel"  >
                     <apex:inputField value="{!opp.Cancel__c}" />



Controller class:

public with sharing class MassEditOppController {

    List<Opportunity> objlist; 

    public ApexPages.StandardSetController OppRecords{

    get {
        if(OppRecords == null) {
            OppRecords = new ApexPages.StandardSetController([SELECT Name, ARP_Action_ID__c, StageName, Expected_Impact_Date__c, Ongoing__c, 
                                     Benefit_End_Date__c, Distributed__c, Cancel__c, Expected_PM_K__c, Cancellation_Reason__c, 
                                     Comment_Reason_for_cancellation__c  FROM Opportunity where Business_Group__c = 'Amcor Rigid Plastics' AND StageName != 'Impact Action' 
                                     AND  StageName != 'Cancelled Action'
                                     AND Expected_Impact_Date__c < TODAY limit 1000 ]); //AND Owner.Id = :UserInfo.getUserId()  limit 1000  ]);  
            return OppRecords;
        private set;

    public MassEditOppController(ApexPages.StandardsetController controller) {


    public List<Opportunity> getObjlist() {

        return (List<Opportunity>)OppRecords.getRecords();

    public List<SelectOption> getCancelOptions(){

        List<SelectOption> options = new List<SelectOption>();
        Schema.DescribeFieldResult fieldResult = Opportunity.Cancellation_Reason__c.getDescribe();

        List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
        for( Schema.PicklistEntry f : ple)
            options.add(new SelectOption(f.getLabel(), f.getValue()));
        return options;

    public PageReference save(){


            pageReference pg = new pageReference('/apex/MassEditOpp_Test');

            return pg.setRedirect(true);

        catch(Exception e) {
            return null;


Test Class:

public class MassEditOppControllerTest {

    static testMethod void myOpportunityMassEditTest() {

        Opportunity objOpp = new Opportunity();

        objOpp.Description__c= 'testOppDesc';
        objOpp.Business_Group__c='Amcor Rigid Plastics';
        objOpp.Business_Unit__c='North America';
        objOpp.Division__c = 'DPD ARP';
        objOpp.Subdivision__c = 'Food';
        objOpp.CloseDate = Date.Today();
        objOpp.Expected_Implementation_date__c = Date.Today();
        objOpp.Expected_Impact_Date__c = Date.Today();
        insert objOpp;

        ApexPages.StandardController sc = new ApexPages.StandardController(objOpp);

        MassEditOppController objC = new MassEditOppController(new ApexPages.StandardController());

        PageReference pageRef = Page.MassEditOpp_Test;


        Opportunity opp1a = [SELECT Id,Expected_Impact_Date__c
                        FROM Opportunity
                        WHERE Id =: objOpp.Id];

        opp1a.Expected_Impact_Date__c = Date.TODAY().addDays(5);
        opp1a.Name = 'testOpp1';
        UPDATE opp1a;



The problem is this line here:

MassEditOppController objC = new MassEditOppController(new ApexPages.StandardController());

There's two problems; first, your constructor uses an ApexPages.StandardSetController, not an ApexPages.StandardController. Second, there's no default constructor for ApexPages.StandardController, either (and it's not what you want anyways).

Since you're not using the ApexPages.StandardSetController anyways, you may as well just pass in a null value:

MassEditOppController objC = new MassEditOppController(null);

You're also not testing your class anyways. Instead of performing a DML on the record you created, you need to call the save method:

PageReference ref = objC.save();

Make sure you're using System.assert, System.assertEquals, and System.assertNotEquals methods. Without those, you're just performing a smoke test, which means you're not interested in verifying the logic of your code and only care about deployment, no matter what bugs may exist in your code.

Do not do this. It will come back to inconvenience you at the most inconvenient time. If you're not sure how to write a proper unit test, please go through this Trailhead. You don't want to have to explain to your bosses and/or stakeholders why production is broken and nobody can use it just because you didn't want to write a proper unit test.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.