0

I am getting an error of "Constructor not defined: [bnkMIS].(ApexPages.StandardController)" in my test class.

Test Class :-

@istest
public class TestbnkMIS {
    public static Testmethod void TestbnkMIS(){
        WorkLog__c wl= new  WorkLog__c();
        wl.Status__c='open';
        wl.AssignDate__c=System.today();
        insert wl;

      Bank_MIS__c  banmis = [Select id FROM Bank_MIS__c];

      Profile CEO = [Select Id FROM Profile Where Name= 'Standard User' limit 1];
        User uc1 = new User(LastName = 'Mohta',
                            FirstName = 'Neha',
                            alias = 'nm',
                            Username = 'nm@techmatrix.com',
                            Email = 'nm@techmatrix.com',
                            ProfileId = CEO.Id,
                            isActive = true,
                            TimeZoneSidKey = 'GMT',
                            LanguageLocaleKey = 'en_US',
                            EmailEncodingKey = 'UTF-8',
                            LocaleSidKey = 'en_US'
                           );

        Branch__c B = new Branch__c();
        B.Name = 'xyz';
        insert B;


        Bank_MIS__c bm = new Bank_MIS__c ();
        bm.INST_Number__c=123456;
        bm.Status__c='Open';
        bm.WorkLog__c=wl.id;
        bm.Process_Date__c=system.today();
        bm.Location_Name__c=B.id;
        bm.P_R_D_Code__c='Cash';
        insert bm;

        PageReference pageRef = Page.BankMISErrorPage;
        apexPages.currentPage().getParameters().put('id',bm.id);
        Test.setCurrentPage(pageRef); 
        ApexPages.StandardController sc = new ApexPages.StandardController(bm); 
        bnkMIS bankcontroller = new bnkMIS(sc);


    }

}

Apex Class :-

public class bnkMIS {
    private ApexPages.StandardSetController standardController;
    public  List<Bank_MIS__c> selectedbnk{get;set;}
    public map<string,List<Bank_MIS__c>> branchBankListMap;
    public map<string,WorkLog__c> branchWorkMap;
    public List<WorkLog__c> wrkList;
    public List<WorkLog_Line_Item__c> wli;
    public bnkMIS(ApexPages.StandardSetController standardController){

          wrkList=new List<WorkLog__c>();
        this.standardController = standardController;
        selectedbnk = new List<Bank_MIS__c>();
        branchBankListMap=new map<string,List<Bank_MIS__c>>();
        branchWorkMap=new map<string,WorkLog__c>(); 
        wli=new List<WorkLog_Line_Item__c>();
                for(Bank_MIS__c bs:  [select Name,INST_Number__c,Status__c,WorkLog__c,Process_Date__c,Location_Name__c,Location_Name__r.Branch_BM__c,Location_Name__r.Branch_BM__r.email from Bank_MIS__c where id In:standardController.getSelected()]){
               if(bs.Status__c=='Error' && bs.Process_Date__c==system.today() && bs.Worklog__c==null){
                  if(branchBankListMap.containsKey(bs.Location_Name__c))
                      branchBankListMap.get(bs.Location_Name__c).add(bs);
                  else{
                     List<Bank_MIS__c> bl=new List<Bank_MIS__c>();
                     bl.add(bs);
                     branchBankListMap.put(bs.Location_Name__c,bl); 
                  }
                  selectedbnk.add(bs); 
             }   
                }
    }

           public PageReference send(){
    try{
            List<Messaging.SingleEmailMessage> theEmails = new List<Messaging.SingleEmailMessage>();
            for(string st: branchBankListMap.keyset()){
                       WorkLog__c wc=new WorkLog__c();
                       wc.AssignDate__c=system.today();
                       wc.AssignTo__c=branchBankListMap.get(st)[0].Location_Name__r.Branch_BM__c;
                       wc.Status__c='Open';
                       branchWorkMap.put(st,wc);
                       wrkList.add(wc);
             }
             insert wrkList;
                  for(string st: branchBankListMap.keyset()){
                 for(Bank_MIS__c bs:branchBankListMap.get(st)){
                     bs.WorkLog__c=branchWorkMap.get(st).id;
                     WorkLog_Line_Item__c wl=new WorkLog_Line_Item__c();
                     wl.Bank_MIS__c=bs.id;
                     wl.WorkLog__c=branchWorkMap.get(st).id;
                     wli.add(wl);             
                 }
                  String body = 'Kindly Check the below link and see Work Log Line Items in your Org which does not contain any Pay Slip.\n';
                  body +='https://cs20.salesforce.com/'+branchWorkMap.get(st).id;
                  Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                  mail.setSubject('Bank Statements does not match with any Payslip');
                  mail.setPlainTextBody(body);      
                  List<String> sendTo = new List<String>();
                  sendTo.add(branchBankListMap.get(st)[0].Location_Name__r.Branch_BM__r.email);   
                  mail.setToAddresses(sendTo);
                  mail.setSenderDisplayName('From Finance Minister');
                  system.debug(mail);           
                  theEmails.add(mail);
             }
               insert wli;
               list<Bank_MIS__c> blst=new List<Bank_MIS__c>();
               for(List<Bank_MIS__c> bl:branchBankListMap.values())
                       blst.addAll(bl); 
               update blst;
                List<Messaging.Email> allMails = new List<Messaging.Email>();
                for( Integer j = 0; j < theEmails.size(); j++ ){
                allMails.add(theEmails.get(j));
                }


                if(!Test.isRunningTest()){
                List<Messaging.SendEmailResult> results = Messaging.sendEmail( allMails );

                 system.debug(results);

                }


         }
         Catch(Exception e){
             system.debug(e);

             }
        return new PageReference('/a1Z');

    }

     }
1

Your Class BnkMIS needs to implement a Constructor with a StandardController parameter as documented here:

public BnkMIS(ApexPages.StandardController stdController) {
    //Bank_MIS__c mis = (Bank_MIS__c) stdController.getRecord();
}

If you need a StandardSetController instead, you need to change it in your Test as describe in the StandardSetController documentation:

List<Bank_MIS__c> records = new List<Bank_MIS__c>{ bm };
ApexPages.StandardSetController ssc = new ApexPages.StandardSetController(records);
4
  • I have added that in my apex class, can you check Nov 17 '17 at 7:49
  • you are using a Set controller: StandardSetController If this is what you need, you also need to use it in your test, where you create the standard controller.
    – Basti
    Nov 17 '17 at 7:50
  • I changed it to StandardSetController in the test class but it is giving me the same error. Nov 17 '17 at 7:57
  • @manchesterunited I updated my answer, does it look like this?
    – Basti
    Nov 17 '17 at 8:01

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.