You need to sign in to do that
Don't have an account?

code coverage for async
I am trying to pass coverage for my async handler below but can't see to catch the error. i have a before trigger that simply passes the message to the global class. This seems to work i write some code in an anoynous block..any thoughts?
my trigger class
catch (Exception ex){
FutureCreateException.createExRecord(ex.getMessage());
Future class
global class FutureCreateException{
@future
public static void createExRecord(string exMessage){
Error_Log__c exceptionRec = new Error_Log__c(Exception_Message__c = exMessage);
insert exceptionRec
}
}
when i run my test class I get the exception but it doesn;t insert it into my error_log__c object so my test class fails. again, when I used anoymous block it works
like this
try{
Order__corder = [SELECT ID FROM Order__c where id='01uW000000HXBNPIA5''];
opp.id = '000000000000000000';
update opp;
}
catch (Exception ex){
FutureCreateException.createExRecord(ex.getMessage());
}
Test.startTest();
//yourtest code here
Test.stopTEst();
i have but it still doesn;t catch it for some reason.
Test.startTest();
integer beforeExCount = [SELECT COUNT()
FROM Error_Log__c];
Opportunity o= MyTestUtils.getCreatedOpp('012300000000100AAA','TestOpp', System.today());
o.id = '000000000000000000';
update o;
Test.stopTest();
integer afterExCount = [SELECT COUNT()
FROM Error_Log__c];
System.AssertEquals(beforeExCount +1, afterExCount );
that was a typo. I am still facing the same issue below. I am expecting this error but I am just nto catching it.
System.TypeException: Invalid id value for this SObject type: 000000000000000000
The main problem is that how come the exception is not getting created in the error_log__c through the test method?
Changing the Id is not the way to do it