You need to sign in to do that
Don't have an account?

do i need to write test class
i am using the after insert,after update,after delete,after undelete events in my trigger while writing test class
do i need to write for each event please advise
do i need to write for each event please advise
trigger quantityleft on Sample_Transaction__c (after insert,after update,after delete,after undelete) { List<Sample_Lot__c> list_lot= new List<Sample_Lot__c>(); set<Id> set_Opportunity = new set<Id>(); if(Trigger.isInsert || Trigger.isUndelete){ for(Sample_Transaction__c objOpp: trigger.new){ if(objOpp.Completed_Transaction__c == true){ set_Opportunity.add(objOpp.Parent_id__c); //set_Opportunity.add(objOpp.id); } } } if(Trigger.isUpdate){ for(Sample_Transaction__c objOpp: trigger.new){ if(objOpp.Completed_Transaction__c == true){ set_Opportunity.add(objOpp.Parent_id__c); // set_Opportunity.add(objOpp.id); } } } if(Trigger.isdelete){ for(Sample_Transaction__c objOpp: trigger.old){ if(objOpp.Completed_Transaction__c == true){ set_Opportunity.add(objOpp.Parent_id__c); } } } if(!set_Opportunity.isEmpty()){ Decimal Sum; Sum=0; for(Sample_Transaction__c sample_transaction : [SELECT id,Completed_Transaction__c,Sample_Lot_ID__c, Transaction_Quantity__c FROM Sample_Transaction__c WHERE Parent_id__c = : set_Opportunity ]){ if(sample_transaction.Completed_Transaction__c ){ system.debug('eeeeeeeeeeeeeeeeeeeeeeeeeeeee'); Sum+= sample_transaction.Transaction_Quantity__c; } for(Sample_Lot__c objLot: [SELECT Id, Quantity_Left__c FROM Sample_Lot__c WHERE Id = : sample_transaction.Sample_Lot_ID__c]){ objlot.Quantity_left__c = Sum ; list_lot.add(objlot); update objLot; } } } }
Yes you need to create ,edit ,delete .undelete records in test method . Your code will give you code coverage for both insert and undelete .
But incase if you have separate scope for undelete then you need to write test case for undelete .
As you have undelete event you should write test case for undelete .
Check below link for undelete event in test case .
https://developer.salesforce.com/forums/?id=906F000000090JXIAY
Thanks
Manoj