2

I am writing a test class for my controller that creates an email using renderStoredEmailTemplate to generate the body and subject. I am wondering if I need to somehow create an email template or should I just use if(Test.isRunningTest()) to conditionally enter a constant value for body and subject? Are the email templates visible in test mode?

1
  • 3
    Have you tried it? Should be quite easy to verify either way. – Adrian Larson Jun 7 '18 at 17:31
4

Yes, email templates are available in unit tests, so you don't need to wall off code with Test.isRunningTest. This will allow you to potentially reach 100% coverage. It also acts as a fail safe in case you accidentally forget to deploy the template, since your test should fail if the template is missing.

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.