You need to sign in to do that
Don't have an account?
test coverage for async
I am trying to assert unexpected exception when a before update trigger fires. I tried this in anonomyous block and my async class is fine and works but how come my assert keeps failing? do i need to wrap that in a try catch too?
before update trigger calls this class
try{
// do some logic
}
catch (Exception x){
FutureCreateException.createExRecord(x.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);
Database.insert(exceptionRec,false);
}
}
test method
test.starttest()
Integer curELogCount= [SELECT COUNT()
FROM Error_Log__c];
Order order = [SELECT ID FROM Order
WHERE ID = '01pW00000004zmpIAA ];
order.id = '000000000000000000';
update order;
test.stoptest()
Integer afterELogCount= [SELECT COUNT()
FROM Error_Log__c];
System.AssertEquals(curELogCount+1, afterELogCount);
I would say, use
insert exceptionRec;
statement in future, if you are creating an exception scenario in your test class