function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Unit testing for simple trigger

I'm at a loss how i can get code coverage with this trigger:
trigger forcemeetingEventtrigger on Event(before insert) {

  Event[] evt=;


Can somebody suggest something at this point that would be useful?  I've read all the docs and examples on unit testing.
You need to create an Apex Class containing a TestMethod that inserts an array of Events.  When the test method is executed (using Run Tests, or on Deploy) it will cause your trigger to fire, giving you code coverage.

I've the same problem.  Can you example the class that would test this trigger and get the trigger into production?
It sounds like the test is going to have more code than the trigger?
Can SOMEONE post an example so that this poor chap and me can both have something to work with.
How do we put tests onto triggers so we can get things out into production?
Thanks in advance.
In order to test this trigger, you need an Apex Class containing a Test Method that causes this trigger to fire, for example:

class EventTriggerTester {

   public TestMethod void testEventTrigger()
      Event evt = new Event();
      evt.Subject = "Call";
      evt.ActivityDateTime =;
      evt.DurationInMinutes = 60;

      insert new Event[]{ event };

      // System.assertEquals( /* ...verify your trigger did what you expected... */ );

This provides a stub, but you'll need to add your own Assert statements to confirm your trigger is working.  Also--I just typed this into the browser without running it, so it's possible minor tweaks will be needed.

After you get this working in your development environment and it's time to deploy to production, make sure to deploy this class and your trigger at the same time, so it all gets included in the set of tests that produce the code coverage results.

Thank-you. Let me see what I can do with this.