0

Trying to call a Class method from a test class:

Class UtilHelper

 global class FeeWrapper {
        global List<Project__c> transToUpdate;
    }

 public static FeeWrapper PassingRentFee(Fee_Calculation__c Config, Project__c trans, List<Project__c> transToUpdate, Map<String, Fee_Mapping__c> m_Fee) 
    

Test class

 Map<String,Fee_Mapping__c > afMap = new Map<String,Fee_Mapping__c >(
            [ SELECT Id, Fee_Amount__c , _Fee_Basis__c , WO__c,Group__c,Type__c,Macro_Type__c 
              FROM Fee_Mapping__c]);
 List<Fee_Calculation__c > feeRec = [
                SELECT Id, Name
                FROM Fee_Calculation__c];
 List<Project__c> projectRec = [
                SELECT Id, Name
                FROM sProject__c];
    
UtilHelper.PassingRentFee rcp = new UtilHelper.PassingRentFee(feeRec[0],projectRec[0],projectRec,afMap); ***error Invalid type***

Is it the parameter I am passing in or is it my syntax. Or both that is causing the error?

1 Answer 1

2

This line contains three errors.

UtilHelper.PassingRentFee rcp = new UtilHelper.PassingRentFee(...);
  1. Invoking new to create an instance requires parentheses:

     UtilHelper.PassingRentFee rcp = new UtilHelper().PassingRentFee(...);
    
  2. The name of the inner class is FeeWrapper, not PassingRentFee.

  3. But your method is static and is not called on an instance at all, but on the class.

The final version should be

    UtilHelper.FeeWrapper rcp = UtilHelper.PassingRentFee(...);
6
  • Thank you David. Ok. So method is Static therefore syntax should be: UtilHelper.PassingRentFee rcp = UtilHelper.PassingRentFee(feeRec[0],projectRec[0],projectRec[0],afMap); If this still throws an Invalid type error should I be looking at my parameters?
    – Phuc
    May 19, 2021 at 14:02
  • Could you edit the complete text of the error into your question?
    – David Reed
    May 19, 2021 at 14:34
  • Here is the error "Error: Compile Error: Invalid type: UtilHelper.PassingRentFee". Does the global feewrapper Class need to be taken in account?
    – Phuc
    May 19, 2021 at 14:37
  • The name of the inner class is wrong. See above.
    – David Reed
    May 19, 2021 at 14:39
  • ok so the feewrapper does come into play. Made update :"UtilHelper.FeeWrapper rcp = UtilHelper.PassingRentFee(feeRec[0],projectRec[0],projectRec[0],afMap);". New error is "Error: Compile Error: Method does not exist or incorrect signature: void PassingRentFee (Fee_Calculation__c, Project__c, Project__c, Map<String,Fee_Mapping__c>) from the type UtilHelper"
    – Phuc
    May 19, 2021 at 14:47

You must log in to answer this question.

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