I am trying to test this (uploaded to pastebin due length) wrapper class. I was trying to follow two previous SFSE's, however I am getting errors. See code below (errors in comments):

public class testAddBasketGasQuoteFromMonitor{
    static testMethod void validateTestMyClass() {
        electricity_meter__c testGasMeter = testUtil.initGasMeter();
    String meterNameInner = String.valueOf( testGasMeter.get('Name') );
    String meterAQ = String.valueOf('100');
    String meterID = String.valueOf('123123123123');  
        AddBasketGasQuoteFromMonitor.WrapperClassEx testWrapperPack = new AddBasketGasQuoteFromMonitor.WrapperClassEx(testGasMeter,meterNameInner,meterAQ,meterID);
        // Error: Constructor not defined: [AddBasketGasQuoteFromMonitor].<Constructor>()
        //AddBasketGasQuoteFromMonitor controller = new AddBasketGasQuoteFromMonitor();
        // Error: Variable does not exist: getwrapperObj
        //for (AddBasketGasQuoteFromMonitor.WrapperClassEx wrap : testWrapperPack.getwrapperObj){}       

Any ideas on what I am doing wrong?

EDIT: Wrapper class code below

public with sharing class AddBasketGasQuoteFromMonitor{
    @TestVisible Public List<WrapperClassEx> WrapperList{get;set;}
    public AddBasketGasQuoteFromMonitor(ApexPages.StandardSetController controller) {
      mycon = controller;
      Selectedmeters = mycon.getSelected();
    public AddBasketGasQuoteFromMonitor(ApexPages.StandardController controller) {
      mycon2 = controller;

    public List<sobject> Selectedmeters {get; set;} 
    ApexPages.StandardSetController mycon;
    ApexPages.StandardController mycon2; 
   @TestVisible Public List<WrapperClassEx> getwrapperObj(){
      id lineId = mycon2.getId();  
      //List<Account> accList = [Select id,name from account limit 5];
      //List<Line_del__c> SelectedLines = [select Linked_Monitor_Line__r.id from Line_del__c where id in: SelectedMeters];
      List<electricity_meter__c> MeterList = [Select id,name,AQ__c,meter_details__c from electricity_meter__c where (Linked_Monitor_Line__c =: lineId)]; 
      WrapperList = New List<WrapperClassEx>();
      for(electricity_meter__c met: MeterList){
        String meterNameInner = String.valueOf( met.get('Name') );
        String meterAQ = String.valueOf( met.get('AQ__c') );
        String meterID = String.valueOf( met.get('meter_details__c') );  
        WrapperList.add(New WrapperClassEx(met,meterNameInner,meterAQ,meterID )); 
      return WrapperList;
Public String options{get;set;}
    // Get the list of suppliers
    public List<SelectOption> getSuppliers(){
        List<SelectOption> options = new List<SelectOption>();        
        Schema.DescribeFieldResult fieldResult =
        List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();        
        for( Schema.PicklistEntry f : ple)
            options.add(new SelectOption(f.getLabel(), f.getValue()));
        return options;

   @TestVisible Public Class WrapperClassEx{
     Public     Account     accObj  {get;set;}
     Public     Sobject     elecObj {get;set;}
     Public     Boolean     checkBox{get;set;}
     Public     string      meterName{get;set;}
     Public     double      dayrate {get;set;}
     Public     string      meterID {get;set;}  
     Public     double      standing{get;set;}
     Public     string      supplier{get;set;} 
     Public     string      AQ      {get;set;}
     Public     string      AQQ     {get;set;}          
     Public WrapperClassEx(sobject accRec, string meterNameMethodVar, string meterAQ, string meterIDs ){
        elecObj = accRec;
        meterName = meterNameMethodVar;

    public List<Quote__C> newQuotes {get; set;}  

    public void save(){  
        newQuotes = new list<Quote__c>();
        for (WrapperClassEx wrap : WrapperList){
            newQuotes.add(new Quote__c(

        try {
            insert newQuotes;
        } catch (DmlException ex){
  • post your wrapper class too.
    – Ashwani
    Feb 24, 2014 at 10:46
  • We can only see the type for the variable testGasMeter, which is electricity_meter__c. Can you confirm that testGasMeter, meterNameInner, meterAQ, meterID are Strings.
    – BarCotter
    Feb 24, 2014 at 10:53
  • testGasMeter is an sObject that I inserted from my utility class. Other variables I removed from this excerpt but now updated.
    – dzh
    Feb 24, 2014 at 11:00

1 Answer 1


The problem is that you try to create an instance of AddBasketGasQuoteFromMonitor with the line AddBasketGasQuoteFromMonitor controller = new AddBasketGasQuoteFromMonitor(); However, your class AddBasketGasQuoteFromMonitor only has a constructor that takes a ApexPages.StandardController as a parameter. So in your test, when you want to create an instance, you have to supply a StandardController.

For example:

PageReference pr = Page.MyPage;
electricity_meter__c testGasMeter = testUtil.initGasMeter();
ApexPages.StandardController stdC = new ApexPages.StandardController((sObject)testGasMeter);

AddBasketGasQuoteFromMonitor controller = new AddBasketGasQuoteFromMonitor(stdC);

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.