Can anyone help me get test coverage for Messaging.SingleEmailMessage?

I'm using email template. Whenever a Case closes, it should send email to Contact.Email and bcc emails of the custom label.

How to assert singleemailmessage in test class?

1 Answer 1


One way to assert on email sent in APEX is to look at the email limits for the transaction. Between your startTest and stopTest you would include an integer to assign Limits.getEmailInvocations(); which will tell you how many invoked emails there are.

Integer i = Limits.getEmailInvocations();

  • I have never been able to get this to work; instead I use this pattern
    – cropredy
    Nov 30, 2019 at 21:44
  • 2
    I've never had any problem with it. Transition cost would be extremely high for a new developer to pick up fflib just for one test.
    – Adrian Larson
    Dec 1, 2019 at 17:22

You must log in to answer this question.

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