I'm currently modifying a test class made by someone because its getting this error. The part at which the error shows up is at the If condition. I'm not sure why it gives that error at that part instead of the previous line. Thanks.

 for(c2g__codaCashEntry__c cashRefund : ppIdToRefundMap.values())
        List<c2g__codaTransactionLineItem__c> transLineList = accIdToReceiptTransLineListMap.get(cashRefund.c2g__Account__c);
            Id jobId = System.enqueueJob(new JVCO_PayonomyMatchRefundQueueable(cashRefund, transLineList));

1 Answer 1


A Map isn't always guaranteed to have the key you are using. In this case, you need to check if the collection is null before checking if it is empty. Often you would know from the structure of your code that it will never be non-null and empty, but you have not shown us the code where accIdToReceiptTransLineListMap gets populated. Regardless, you need to add a null check before your empty check:

if (myList != null && !myList.isEmpty())

You must log in to answer this question.

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