I've created a simple trigger that posts a user's field entries to chatter whenever they create or update a new record on the Weather Tracker custom object. It works. The problem I have is writing test code. My test code doesn't fail, but when I view my trigger's code coverage, it says 0%. What am I missing??



1 Answer 1


You are never inserting your weather_tracker__c record. Add this statement to your test method

insert wt;

after you set the air_temp__c field.

  • Also, make sure you are running your test classes in async method. If you goto developer console and Test -> Always Run Asynchronously should be checked.
    – SL man
    Nov 10, 2015 at 16:49
  • Yeah, I figured that part out after reading through other examples. But now, just before that insert, I have a required field that's part of the master-detail relationship. It's the name field. The selection would be 'JAN-9', for example. How do I populate this field with a selection from a related object?
    – Rocket_Izz
    Nov 10, 2015 at 16:56
  • If weather_tracker__c is the detail int he master-detail relationship, you'll need to create a parent object, insert it, and then associate the records. Populate the master-detail field on the child, with the Id of the parent.
    – vreeder
    Nov 10, 2015 at 17:14
  • I just went ahead and eliminated the relationship. I wasn't absolutely sure that it was needed anyway. This moved my code coverage to 100%. Thanks for the help bro. I checked your response as the answer :)
    – Rocket_Izz
    Nov 10, 2015 at 17:19

You must log in to answer this question.

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