+ Start a Discussion

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){


Future class

global class FutureCreateException{
   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 

Order__corder = [SELECT ID FROM Order__c where id='01uW000000HXBNPIA5''];
opp.id = '000000000000000000';
update opp;

catch (Exception ex){

haev you enclosed your code in
//yourtest code here

i have but it still doesn;t catch it for some reason.

            integer beforeExCount = [SELECT COUNT() 
                                           FROM Error_Log__c];   
            Opportunity  o= MyTestUtils.getCreatedOpp('012300000000100AAA','TestOpp', System.today());      

            o.id = '000000000000000000';
            update o;
            integer afterExCount = [SELECT COUNT() 
                                           FROM Error_Log__c];             
            System.AssertEquals(beforeExCount +1, afterExCount ); 

Well you changed the id for variable "opp" but updated "o"

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?


If you are changing the Id and updating the record. THe error will be generated in test class not in the trigger code. Because it never made it to the trigger.

Changing the Id is not the way to do it