+ Start a Discussion

Unit test a trigger calling a class

I am now onto unit testing my class called from a trigger that I got help with a few weeks back. As you all know, I need to have unit tests proving successful coverage of my code.  From the help & online, I figured out how to setup Eclipse & the Force.com IDE.


Currently, I am connected to our sandbox:


Here is the trigger.  it calls a method in a class:

trigger ReportPackageTrigger on Report_Package__c (after update) {



I created a 'test' class, and from the help, I discerned that I need to create & reference instances of the objects that will be used to initiate an update event.  I am quite new to the SF paradiagm being more familiar with .Net methods, but am muddling my way through.  I need allot of help with the concept's implementation of how to properly set up a unit test with appropriate coverage.  In SANDBOX This is what I have so far, but it is incomplete, I know.  Would anyone be able to steer me in the right direction on how to build a caompleted unit test?  Additional resources would also be welcomed!



private class UnitTestClass {

    static testMethod void TestEndDatingPkg() {
      //Comment: Set up a dummy Package recipient with today as the start date.
      Package_Recipient__c PackRecp = new Package_Recipient__c(Contact_Name__c='Albrecht',Start_Date__c=Date.today());
      insert PackRecp;
      //Comment: Set up a dummy Package with no end date.
      Report_Package__c RepPkg = new Report_Package__c(name='ABC Package');
      insert RepPkg;


//I need to now associate the recipient with the package, assign a date to a field, which will be an event that I will catch in my class code.


Force TechieForce Techie

Hi KevinA,


Your trigger is on After update event so you have to update your test object record in test class. Please, tell what is your helper class is doing after that i'll convienent to tell what you have to do.