+ Start a Discussion

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


 // do some logic
catch (Exception x){


Future class

global class FutureCreateException{
   public static void createExRecord(string exMessage){
         Error_Log__c exceptionRec = new Error_Log__c(Exception_Message__c = exMessage);


test method


 Integer curELogCount= [SELECT COUNT() 

                                             FROM Error_Log__c];


Order order = [SELECT ID FROM Order

                          WHERE ID = '01pW00000004zmpIAA ];
order.id = '000000000000000000';
update order;


Integer afterELogCount= [SELECT COUNT() 
                                             FROM Error_Log__c];


  System.AssertEquals(curELogCount+1, afterELogCount);






Bhawani SharmaBhawani Sharma
In your future class, you are using Database.insert(exceptionRec,false);. This statement allows partial insert. Having said that, if a record get failed in insertion, cursor will move to the next record silently.
I would say, use
insert exceptionRec;
statement in future, if you are creating an exception scenario in your test class