You need to sign in to do that
Don't have an account?
SidVicious
Code Coverage for Test Class for Undelete in Apex
Hi, everyone. I've hit yet another issue with code coverage for Test classes. This time it's about the Undelete operation.
Trigger
Test class
Apex class
I'm not able to get code coverage for below line in my Apex class (shown on the code snippet above):
My assertion above passed, so I know I have the list of Invoice Line records - yet I'm not able to get code coverage for this Undelete operation.
I'd appreciate any ideas/suggestions on how to resolve this.
Thanks!
- Sid
Trigger
trigger InvoiceLineTrigger on InvoiceLine__c (before insert, before update, before delete, after undelete) { new InvoiceLineTriggerHandler().run(); }
Test class
@isTest private static void undeleteInvoiceLines(){ initializeData(); // populates all needed records System.assertNotEquals(0, invoiceLineList.size()); insert invoiceLineList; delete invoiceLineList; Test.startTest(); try { undelete invoiceLineList; }Catch(Exception e) { String errormessage = e.getMessage(); system.debug(errormessage); } Test.stopTest(); }
Apex class
public override void afterUndelete() { for(InvoiceLine__c invLine : (List<InvoiceLine__c>) Trigger.old){ if(invLine.InvoiceId__c != null){ invLineIdSet.add(invLine.InvoiceId__c); } } }
I'm not able to get code coverage for below line in my Apex class (shown on the code snippet above):
if(invLine.InvoiceId__c != null){ invLineIdSet.add(invLine.InvoiceId__c); }
My assertion above passed, so I know I have the list of Invoice Line records - yet I'm not able to get code coverage for this Undelete operation.
I'd appreciate any ideas/suggestions on how to resolve this.
Thanks!
- Sid
There is nothing old when you undelete any records. It is just similar to the insert case. Please change the apex class as below: Let me know if this works for you.
Thanks,
Abhishek Bansal.