2

My trigger is receiving 0% coverage and I am unable to deploy.

The problem is, if triggered with success, it sends out an email.

The email method is a @future method.

Is there anyway in Apex to test if a method was called or fired?

4

You can get number of future calls using syntax Limits.getDMLStatements();. In test class probably you can assert like below,

Test.startTest();
//Your test code here
Test.stopTest();
System.assertEquals(Limits.getFutureCalls(),1);
System.assertEquals(Limits.getEmailInvocations(),1);

Please remember that asynchronous calls from test class will be executed after Test.stopTest();. So make sure to add Test.StopTest() and assert statements after that

| improve this answer | |
  • Just an aside, how do I clear code coverage in dev mode? – Ali Gajani May 29 '15 at 19:37
  • Each time when you run test class, previous coverage will be reset and new coverage will be shown – Victor May 29 '15 at 19:38
  • What is .getFutureCalls(), is that a SF method? – Ali Gajani May 29 '15 at 19:39
  • yeah. Check salesforce.com/us/developer/docs/apexcode/Content/… – Victor May 29 '15 at 19:39
  • Okay, have been getting this since many hours now SubscriptionTrigger, Details: Test coverage of selected Apex Trigger is 0%, at least 1% test coverage is required. I have this trigger which sends emails only if a campaign is selected. But the code coverage remains 0%. Any way to bypass this? My code is already covering the case, yet it's 0% – Ali Gajani May 29 '15 at 19:52

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.