0

I have a flow that is triggered when an Opportunity is created. I'm trying to debug the flow by having it send me an email with values. When I create a record from the UI it works just fine. But when I create a record by running a test class in apex I do not get an email.

There was a setting to turn on emails in the sandbox. I have done that, which is why I can get emails when creating normally.

Is there something about doing it in apex or doing a test class that prevents emails? Is there a good way to test flow automation when a record is created by apex?

4

It is by design that actual emails will not be fired from test class calls...but you should still be getting code coverage if the method is called.

You can "test" that your email code is working correctly by using the Limits.getEmailInvocations(); twice, once before calling Test.startTest() and once after Test.stopTest(), and recording the difference(going from 0 to 1 email invocation for example).

There is already QUITE a bit of documentation and cases where users have run into this, but the particular resource I used was:

https://developer.salesforce.com/forums/?id=906F0000000kFJZIA2

1

Test classes leave no side effects at all, except for debug logs and code coverage records. This means that any emails that would have been sent by the flow are cancelled and not really sent. You'd be better off saving the data to a custom object and then querying the data back from the database after your flow runs.

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.