0

I'm stumped - I have a simple test routine that creates contacts but when I deploy, the contact trigger has zero coverage.

The trigger is about 55 lines of executable code, here's the relevant part...

trigger ContactTrigger on Contact (before insert, before update, before delete, after insert, after update, after delete, after undelete) {
    // SNIP 
    if (trigger.isAfter){
        if (trigger.isDelete) greetings.updateGreetings(trigger.old);
        else greetings.updateGreetings(trigger.new);
    }
}

Below is the crux of my test class. Despite inserting nine contacts, the trigger isn't getting any coverage. I've already tried re-deploying, no luck.

@isTest
private class Greetings_test {

    @isTest static void test_composite() {
        contact cyn = new contact(lastname='Einstein', firstname='Cynthia');
        insert cyn;
        contact[] cynList = [select id, accountid from contact where lastname='Einstein'];
        id acct = cynList[0].accountid;

        list<contact> family = new list<contact>();
        family.add(new contact(lastname='Tesla', firstname='steve',  accountid=acct));
        family.add(new contact(lastname='tesla', firstname='ella',  accountid=acct));
        family.add(new contact(lastname='Tesla', firstname='elroy',  accountid=acct));
        family.add(new contact(lastname='tesla', firstname='tormo',  accountid=acct));
        family.add(new contact(lastname='tesla', firstname='ty',   accountid=acct));
        family.add(new contact(lastname='tesla', firstname='cougar',  accountid=acct));
        family.add(new contact(lastname='einstein', firstname='sarto',   accountid=acct));
        family.add(new contact(lastname='einstein', firstname='tasha', accountid=acct));
        insert family;
    }
}
  • How about in development sandbox? is it showing some coverage? – RKM Jul 19 '18 at 7:11
  • Also make sure that you have at least one executable statement in Trigger apart from debug statement. – RKM Jul 19 '18 at 7:20
  • Please check your test class coverage in sandbox and respective test class for trigger – SFDC FAN Jul 19 '18 at 7:27
  • Thanks to everyone for the quick help, especially @Rohit! I've updated the question to include more of the trigger. It is more than shell - it has 55 lines of executable code. In the sandbox I get about 27% coverage. It's that low because most of it is about other topics. – sberley Jul 19 '18 at 16:16
  • 1
    Does the test pass? Is it possible that you have more than one trigger and one of them is throwing an exception prior to executing your class? Your test class is not performing a delete, so you shouldn't expect coverage on your delete logic. – David Reed Jul 19 '18 at 16:18
1

I actually tried to reproduce your case, If you do not have any executable statement It shows 0% coverage. See below:

enter image description here

Now I just create an instance of Class or object Account, see below snips, It shows 100% coverage. SO can you make sure that you have atleast one executable statement in your Trigger.

enter image description here

enter image description here

0

Big call out to @[David Reed] - he nailed it!

The org includes a very large managed package/application and something outside of my code must have tripped before getting to my trigger.

Typically - I deploy with the "Run specific tests" option and hand it my test classes. This has never failed me, until now.

By deploying using the "Default" the test phase took WAY longer, but worked perfectly.

Thanks to all for the help!

Steve

Oakland, Calif.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.