function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
LaaralLaaral 

Compile Error: Method does not exist or incorrect signature

Hi, I have trigger that's meant to calculate SLA minutes using BusinessHours.


Now I keep getting this error : Compile Error: Method does not exist or incorrect signature BusinessHours.diff(Id, Datetime, Decimal) at line 32 column 46

and I don't understand what is wrong here? (Highlighted sentence)

 

trigger CaseResolutionTimeTrigger on Case (before update) {
    
    if (Trigger.isUpdate) {
        
        for (Case updatedCase:System.Trigger.new) {
            System.Debug('CaseResolutionTimeTrigger: CASE ID: ' + updatedCase.Id);           
                        
            RecordType recordType = [select Id, Name from RecordType where SObjectType = 'Case' and Name = 'Support' LIMIT 1];
            
            System.Debug('CaseResolutionTimeTrigger: FETCHED RECORD TYPE: ' + recordType.Id );
            System.Debug('CaseResolutionTimeTrigger: RECORD TYPE IN CASE: ' + updatedCase.RecordType.Id );
            
            // Get old Case data. We are also only interested in Support Cases.
                 if (System.Trigger.oldMap.get(updatedCase.Id) != null /*&& updatedCase.RecordType == recordType*/ ) {
            
                Case oldCase = System.Trigger.oldMap.get(updatedCase.Id);            
                System.Debug('CaseResolutionTimeTrigger: OLD STATUS: ' + oldCase.Status);
                System.Debug('CaseResolutionTimeTrigger: NEW STATUS: ' + updatedCase.Status);
                  if (updatedCase.Date_and_time_of_resolution__c!= null && updatedCase.Related_Setup__c != null && updatedCase.Resolution_time__c == null ||(oldCase.Date_and_time_of_resolution__c!= updatedCase.Date_and_time_of_resolution__c)) {
                    
                    // Related Setup
                    Setup__c relatedSetup = [select Id, Contract__c, Cost_Center__c, Name, Service_Availability__c from Setup__c where Id =: updatedCase.Related_Setup__c];
                    System.Debug('CaseResolutionTimeTrigger: Related Setup: ' + relatedSetup.Name);
                    
                    // Get BusinessHours from Setup -> Contract-> Contract(Agreement) -> Business Hours
                    ServiceAvailability saHelper = new ServiceAvailability();
                    Id hoursToUse = saHelper.GetHoursToUse(updatedCase, relatedSetup);
                    if(hoursToUse != null ) {                                       
                        System.debug('CaseResolutionTimeTrigger: HOURS TO USE: ' + hoursToUse);
                                        
                     //Double ResolutionTime = Initial_Response__c.GetTime() - Date_and_time_of_resolution__c.GetTime();
                     Double ResolutionTime = BusinessHours.diff(hoursToUse, updatedCase.Initial_Response__c,updatedCase.Resolution_time__c);
                     Double rmMins = resolutionTime / 60000.0;
                     Double rmHrs = resolutionTime / 60000.0 / 60;
                     Double rmDays = resolutionTime / 60000.0 / 60 / 24;
                        
                     System.Debug('CaseResolutionTimeTrigger: RESPONSE TIME (ms): ' + resolutionTime);
                     System.Debug('CaseResolutionTimeTrigger: RESPONSE TIME (mins): ' + rmMins);
                     System.Debug('CaseResolutionTimeTrigger: RESPONSE TIME (hrs): ' + rmHrs);
                     System.Debug('CaseResolutionTimeTrigger: RESPONSE TIME (days): ' + rmDays);                     
                        
                     updatedCase.Resolution_time__c = rmMins;
                     // update updatedCase
                     
                  } else {
                        
                     System.Debug('SETUP NOT FOUND: ' + updatedCase.Related_Setup__c);
                   }
                }
            }
        }
    }
}

ManojjenaManojjena

 Id hoursToUse = saHelper.GetHoursToUse(updatedCase, relatedSetup);  LIne 27 ...

 

Make String hoursToUse = saHelper.GetHoursToUse(updatedCase, relatedSetup);

 

Please check Initial_Response__c,Resolution_time__c two fields are  with data type DataTime  or Date.

As the diff method takes DateTime and String .

 

check once .

LaaralLaaral

Hi, I was just thinking that now the Resolution_time__c is decimal, so the data type is number. This field should contain calculated minutes, so can I make it a date or date/time type?

 

 

 

LaaralLaaral
Also I tried to change the ID to string but I get the same answer as : Compile Error: Method does not exist or incorrect signature: BusinessHours.diff(String, Datetime, Decimal) at line 32 column 46
souvik9086souvik9086

Double ResolutionTime = BusinessHours.diff(hoursToUse, updatedCase.Initial_Response__c,updatedCase.Resolution_time__c);

 

Make 

hoursToUse = String Type(by casting like String.valueOf())

updatedCase.Initial_Response__c = Make it DateTime by casting like above

updatedCase.Resolution_time__c = Make it Decimal by casting to Decimal

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks