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
IKZIKZ 

Test class error: Illegal assignment from String to Decimal

I’m trying to write a test class for class calculating business hours
In CaseTriggerHandler we have:
public void beforeUpdate(SObject oldSo, SObject so){
 
        CaseTriggerHelper.calculateBusinessHours((Case)oldSo, (Case)so);
    }

And in CaseTriggerHelper:
public static void calculateBusinessHours(Case oldCase, Case newCase){
        if (oldCase.Initial_FCO_Date__c != newCase.Initial_FCO_Date__c && newCase.Initial_FCO_Date__c != null ){
            Double timeSinceLastStatus = BusinessHours.diff(newCase.BusinessHoursId, newCase.CreatedDate, newCase.Initial_FCO_Date__c)/3600000.0;
            newCase.Business_Hours_FCO_Created_CreateDate__c =timeSinceLastStatus;
        }
    }
}

and in my CaseTriggerHandlerTest so far I got:
static testMethod void testCalculateBusinessHours() {
	    SetupDataClass setup_data = new SetupDataClass();
		setup_data.upsertTestCases();
        System.runAs(setup_data.TestUser){

            Test.startTest();
                Case test_case = [SELECT Id, CreatedDate, Initial_FCO_Date__c, Business_Hours_FCO_Created_CreateDate__c FROM CASE WHERE Id = :setup_data.TestCase.Id];
				BusinessHours calculateBusinessHours = [SELECT Id FROM BusinessHours WHERE IsDefault=true];
				
				for(Case case_to_update : setup_data.TestCases){
                    case_to_update.CreatedDate = Datetime.now().addDays(-1);
                    case_to_update.Initial_FCO_Date__c = Datetime.now();
					case_to_update.Business_Hours_FCO_Created_CreateDate__c = '8.50';
			Test.stopTest();
			
			for (Case updated_case : setup_data.TestCases) {
            System.assertEquals(setup_data.TestUser.Id, test_case.CreatedDate != NULL);
			System.assertEquals(setup_data.TestUser.Id, test_case.Initial_FCO_Date__c != NULL);
				}
			}
        }
    }
Error: Compile Error: Illegal assignment from String to Decimal at line 60 column 21    

that's: 
System.assertEquals(setup_data.TestUser.Id, test_case.CreatedDate != NULL);

thank you

 
Bryan Leaman 6Bryan Leaman 6
Are you sure about which line that line number corresponds to? I'd expect an error like this on that line:
Comparison arguments must be compatible types: Id, Boolean

setup_data.TestUser.Id looks like it should be an Id field and "test_case.CreatedDate != NULL" is a boolean.
Raj VakatiRaj Vakati
Try this
 
static testMethod void testCalculateBusinessHours() {
	    SetupDataClass setup_data = new SetupDataClass();
		setup_data.upsertTestCases();
        System.runAs(setup_data.TestUser){

            Test.startTest();
                Case test_case = [SELECT Id, CreatedDate, Initial_FCO_Date__c, Business_Hours_FCO_Created_CreateDate__c FROM CASE WHERE Id = :setup_data.TestCase.Id];
				BusinessHours calculateBusinessHours = [SELECT Id FROM BusinessHours WHERE IsDefault=true];
				
				for(Case case_to_update : setup_data.TestCases){
                    case_to_update.CreatedDate = Datetime.now().addDays(-1);
                    case_to_update.Initial_FCO_Date__c = Datetime.now();
					case_to_update.Business_Hours_FCO_Created_CreateDate__c = 8.50;
			Test.stopTest();
			
			for (Case updated_case : setup_data.TestCases) {
            System.assertEquals(setup_data.TestUser.Id, test_case.CreatedDate != NULL);
			System.assertEquals(setup_data.TestUser.Id, test_case.Initial_FCO_Date__c != NULL);
				}
			}
        }
    }

 
IKZIKZ
Yes, thats the line:
System.assertEquals(setup_data.TestUser.Id, test_case.CreatedDate != NULL);

any suggestions how I can fix that?
IKZIKZ
that gives me Comparison arguments must be compatible types: Id, Boolean at line 64 column 20 64 being: System.assertEquals(setup_data.TestUser.Id, test_case.CreatedDate != NULL);
IKZIKZ
that gives me 
Comparison arguments must be compatible types: Id, Boolean at line 64 column 20
64 being: System.assertEquals(setup_data.TestUser.Id, test_case.CreatedDate != NULL);