I am trying to cover wrapper class defined in controller extension.But I am getting Error:

Compile Error: Invalid type: testinvoice.wrapperItem at line 60 column 8

Apex class:

public without sharing class IITUpdateInvoice_EXT {
    public List<wrapperItem> milestoneList = new List<wrapperItem>();
    public list<Payment_Schedule_CELG_IIT__c > updmilestone= new 
    List<Payment_Schedule_CELG_IIT__c >();

    public IITUpdateInvoice_EXT(ApexPages.StandardController controller) {

    Set<ID> mileId = new Set<Id>();
    ID studID = [Select Study_CELG_IIT__c from Payments_and_Invoicing_CELG_IIT__c where id=: Apexpages.currentPage().getParameters().get(IIT_Utility.Id_Param) limit 1].Study_CELG_IIT__c ;
    List<Payment_Schedule_CELG_IIT__c > payList = [Select id,name,Payment_Amount_CELG_IPS__c from Payment_Schedule_CELG_IIT__c where Study_CELG_IIT__c =: studID   limit 200];
    List<Payment_Milestone_Invoice_Association__c> junctionList = [Select id, Invoice_IMG__c,Payment_Milestone_IMG__c from Payment_Milestone_Invoice_Association__c where Invoice_IMG__c =:Apexpages.currentPage().getParameters().get('if')]; 
    Public List<wrapperItem> getMilestoneObj(){

        for(Payment_Milestone_Invoice_Association__c junc: junctionList ){
        for(Payment_Schedule_CELG_IIT__c  payment : payList){
                milestoneList.add(new wrapperItem(payment ,false));
        return Milestonelist;

    /* Wrapper Class to Display all Payment Milestones records with selected checkbox */
    public class wrapperItem{

        public Payment_Schedule_CELG_IIT__c  milObj{get;set;}
        public Boolean selectBox{get;set;}

        @TestVisible public wrapperItem(Payment_Schedule_CELG_IIT__c  milRec,Boolean checkBox){
            milObj = milRec;
            selectBox= checkBox; 


    /* Associate selected Payment milestones record to the Invoices */
    public void saveRec(){

        List<Payment_Milestone_Invoice_Association__c > juncList = new List<Payment_Milestone_Invoice_Association__c>();
        for(wrapperItem wrap:Milestonelist){

            if(wrap.selectBox == true){

                Payment_Milestone_Invoice_Association__c junc = new Payment_Milestone_Invoice_Association__c();
                junc.Payment_Milestone_IMG__c = wrap.milObj.id;

                database.insert( juncList,true);
            }catch(Exception e){


Test class:


private class IITUpdateInvoiceTest{

    static testMethod void testIITUpdateInvoice(){

        Id approvedRecordTypeId = Schema.SObjectType.study_celg_ips__C.getRecordTypeInfosByName().get('Approved IIT Study').getRecordTypeId();
        Id pubProfileId = [select id from profile where name ='Superuser_CELG_IPS_Pub'].id;
        Id personAccountRecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Health Care Professional').getRecordTypeId();
        user usr = [select id from user where profileId=:pubProfileId and isActive=true limit 1];

            study_celg_ips__c oldStd= new study_celg_ips__C();
            insert oldStd;

        product2 prod = new product2(name ='test',Approved_for_IITs__c=true,IsActive=true);

        insert prod;

        ID productId = [select id from product2 where id=:prod.id].id;

        Journal_Congress_CELG_IPS__c journal = new Journal_Congress_CELG_IPS__c(name='test');

        insert journal;

        ID journalID = [select id from Journal_Congress_CELG_IPS__c where id=:journal.id].id;

        study_celg_ips__c std = new study_celg_ips__C(recordtypeid= approvedRecordTypeId,Target_journal_CELG_IIT__c=journalID,                         Will_support_be_requested_CELG_IPS__c='No',Outcome_CELG_IPS__c='Ready for IRC',Outcome_Full_Concept_CELG_IIT__c='Approved' );

        insert std;

        ID studId = [select id from study_celg_ips__c where id=:std.id].id;

        Payments_and_Invoicing_CELG_IIT__c invoice = new Payments_and_Invoicing_CELG_IIT__c(Invoice_Number_CELG_IIT__c='123',Study_CELG_IIT__c=studId,Invoice_Amount_CELG_IIT__c=100);

        insert invoice;

        ID invoiceId = [select id from Payments_and_Invoicing_CELG_IIT__c where id=:invoice.id].id;

        Payment_Schedule_CELG_IIT__c paymentMilestone = new Payment_Schedule_CELG_IIT__c(Name ='test',Study_CELG_IIT__c=studId);

        insert paymentMilestone;

        ID paymentMilestoneId = [select id from Payment_Schedule_CELG_IIT__c where id=:paymentMilestone.id].id;

        Payment_Milestone_Invoice_Association__c association = new Payment_Milestone_Invoice_Association__c(Invoice_IMG__c=invoiceId ,Payment_Milestone_IMG__c=paymentMilestoneId );

        insert association ;

        PageReference pageRef = Page.IIT_Update_Invoice;
        pageRef.getParameters().put('id', invoiceId );

        IITUpdateInvoice_EXT testinvoice = new IITUpdateInvoice_EXT(new ApexPages.StandardController(invoice));
        Payment_Schedule_CELG_IIT__c  mile = new Payment_Schedule_CELG_IIT__c();
        Boolean check = true;
        testinvoice.wrapperItem wrap = new testinvoice.wrapperItem(mile,check);




1 Answer 1


Question 1:

Your creating child class with parent class instance.trying doing this, Create child class instance with parent class Name.

Syntax: OuterClass.InnerClass innerObject = new OuterClass.InnerClass();

  IITUpdateInvoice_EXT.wrapperItem wrap = new IITUpdateInvoice_EXT.wrapperItem(mile,check);

Question 2 :

In test Class call First


Followed By


because your Milestonelist generated by testinvoice.getMilestoneObj() and used in testinvoice.saveRec();

Finally code will look like this

    IITUpdateInvoice_EXT testinvoice = new IITUpdateInvoice_EXT(new ApexPages.StandardController(invoice));
    Payment_Schedule_CELG_IIT__c  mile = new Payment_Schedule_CELG_IIT__c();
    Boolean check = true;
    IITUpdateInvoice_EXT.wrapperItem wrap = new IITUpdateInvoice_EXT.wrapperItem(mile,check);

Question 3:

Reason behind your not able to pass the if statement because your setting false to selectBox in wrapperItem in the below statement and adding same wrapperItem to milestoneList.

   milestoneList.add(new wrapperItem(payment ,false));

And same milestoneList your checking for selectBox for true. either change the statement to

   milestoneList.add(new wrapperItem(payment ,true));


If your can't change original class code then you have update the wrapperItem of Milestonelist after calling testinvoice.getMilestoneObj();

something like this,

  public List<wrapperItem> TempMilestoneList = new List<wrapperItem>();
  For(wrapperItem item:testinvoice.milestoneList ) {
       wrapperItem TempItem=item;     //Avoid modify original object inside iteration , it **throw run time error**. So i create new **TempItem** and **TempMilestoneList** 

Best-practice-for-test-classes [Reference]

  • Okay @NITHESH,it is covering wrapper class.But I have one more question.I am using testinvoice.saveRec(); in test class, but it is not covering the line` for(wrapperItem wrap:Milestonelist){` in apex class. can you tell me is there anything else that I am missing
    – devsfdc
    Commented Aug 8, 2017 at 6:45
  • @devsfdc I have updated the answer.
    Commented Aug 8, 2017 at 7:15
  • Thanks @NITHESH, for(wrapperItem wrap:Milestonelist){ is getting with your code,but after that code is comapring checkbox field to TRUE if(wrap.selectBox == true){ .How can I replicate this checkbox update in test class.
    – devsfdc
    Commented Aug 8, 2017 at 7:22
  • @devsfdc I have updated the answer
    Commented Aug 8, 2017 at 7:35
  • Your Welcome...
    Commented Aug 8, 2017 at 8:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .