-1
for (APC_I_c rAPC : scope) {
        rAPC.Error__c = null;
        rAPC.Type_of_Error__c = null;
        rAPC.Status__c = 'Processed';
        if(rAPC.APC_ID_Account_RCS__c != null){
                 
            try{
                Account acc =  new Account();
                acc.APC_Id__c = rAPC.APC_ID_Account_RCS__c;           
                acc.Name = rAPC.Account_Name__c;
                lstaccAPC.add(acc);
                
            }catch(Exception exc){
                APC_I_Batch_Helper.processError(rAPC,exc.getMessage()); 
                
2
  • i want to test it but the test doesn't cover that catch
    – lulu88
    Nov 11, 2020 at 20:25
  • 1
    It looks quite possibly to be a situation where you are catching errors which cannot occur.
    – Adrian Larson
    Nov 11, 2020 at 20:28

1 Answer 1

1

Remove the try-catch block. It is not possible to have an exception here. Generally speaking, if you're having problems trying to cover a try-catch block, it is either untestable, or unnecessary. It's important to learn when exceptions can occur in order to catch them effectively. Also see Pokemon Catch - Generic Exception Handling In Apex and Test Code coverage catch block, as well as Can batchable custom iterables support null values?, in which I discover that scope will never contain null values.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .