0

I'm trying to write test class for my Apex lass but I'm getting an error at the last line.

Error: Compile Error: Method does not exist or incorrect signature: void beforeInsert(Call__c) from the type CallTriggerService at line 45 column 38

Please suggest my Test calss is correct or any mismatches exist.Please help?

Apex Class :

 public class CallTriggerService {

  public static void beforeInsert(List<Call__c> triggerNew){
  
    Id currUsrId = UserInfo.getUserId();

    for(Call__c c: triggerNew){
    
        c.ZTS_EU_Call_Owner__c = UserInfo.getUserId();
                    
        String str = '0.5 Hours';
        List <String> strList = str.split(' ');
        String str1 = strList[0];
        str1 = str1.trim();
        Double minutes = Double.valueOf(str1) * 60;
        if(c.ZTS_EU_Start_Date_Time__c != NULL){
        
            c.ZTS_EU_End_Date_Time__c = c.ZTS_EU_Start_Date_Time__c.addMinutes(Integer.valueOf(minutes));
        
       }
    
    } 
}

Test Class :

@isTest
private class  CallsTest{

    @isTest static void caluclateTime(){
        
        //Create an US User
        
        Profile p = [SELECT Id FROM Profile WHERE Name='US Livestock Rep'];
        
        User u = new User(Alias = 'FAINR', Email='[email protected]', 
            EmailEncodingKey='UTF-8', LastName='Fain', LanguageLocaleKey='en_US', 
            LocaleSidKey='en_US', ProfileId = p.Id,TimeZoneSidKey='America/Los_Angeles', UserName='[email protected]');
            
        insert u;

        System.runAs(u) {
        
               //Create an Account
                
                Account acc = new Account();         
                acc.name = 'Test Account';
                acc.ZTS_US_Business_Class__c = 'Sub-Class 1';
                acc.ZTS_EU_Country__c = 'United States';
                acc.BillingCity = 'Test City';
                acc.ZTS_US_State_Province__c  = 'Ohio';
                acc.BillingStreet = 'Test Street';  
                acc.ZTS_US_NARC_ID__c='12345');
                insert acc
                
                         
                //Create one Call
            
                Call__c call = new Call__c();
                call.ZTS_EU_Account__c = acc.Id;
                call.Name = 'Test Call';                

                dateTime dt = system.now();
                call.ZTS_EU_Sub_Type__c = 'Account Call';
                call.ZTS_EU_Start_Date_Time__c = dt+3;
                call.ZTS_EU_End_Date_Time__c = dt+4;
                call.ZTS_EU_Status__c = 'Submitted';
                call.ZTS_EU_Duration__c = '0.5 Hour';
                insert call;    
                
                This line I'm getting error 
                
                Compile Error: Method does not exist or incorrect signature: void beforeInsert(Call__c) from the type CallTriggerService at line 45 column 38   

                
                CallTriggerService.beforeInsert(call);
                        
        }
        
    }
    
}

Thanks, Basha

1 Answer 1

1

To compile, the method requires a list to be passed in. The list can contain any number of items, so one way to do that from your test is:

CallTriggerService.beforeInsert(new List<Call__c>{call});

Do also add assertions after the call to confirm the expected results.

(As Nagendra Singh commented in their answer to Error: Compile Error: Extra ')', an explicit call is usually not needed. In this case the line insert call; will result in the handler code running assuming there is a trigger calling the handler class.)

You must log in to answer this question.

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