Other than the official documentation and related SFSE questions indicate the Error reporting of Second Generation Managed Packages (2GP) seems to behave differently that with 1GP.

I want to make this tool work with 2GP Managed Packages: https://github.com/rsoesemann/lma-app-cockpit but couldn't get a 2GP Managed Package that was created using the errornotificationusername parameter to send notification emails on Unhandled Apex Errors.

Is this supposed to work or did I discover a bug?

  • 3
    Is there a question in here somewhere, or just info sharing? Did you raise a support case with Salesforce?
    – Phil W
    Mar 1, 2022 at 16:46
  • 1
    You are right. Added a question if this is a bug or supposed to work. I will also create a support case and put the Id here later. Mar 1, 2022 at 17:12

2 Answers 2


Yes, unhandled exception emails do work with 2GP.

I confirmed this by creating a managed 2GP with a Visualforce Controller that tries to divide by zero if a certain custom metadata record is set to true.

Here's how I set up my test:

  1. Created managed 2GP using force:package:create.
  2. Used force:package:update with the --ERRORNOTIFICATIONUSERNAME flag and provided the username of a user from the DevHub that I used to create the 2GP.
  3. Created and promoted a package version with my test code
  4. Installed the package version in an ACTIVE (i.e. production) Enterprise Edition org.
  5. Performed an action that triggered the unhandled exception.

Figure 1: Unhandled Exception in the Subcriber Org

Unhandled Apex exception in the subscriber org.

Figure 2: Unhandled Exception Email Received ~5 Minutes Later

enter image description here

Possible Reasons for Missing Unhandled Exception Emails

This Known Issue highlights the fact that Apex exception emails are rate-limited to a few hundred emails per hour for a given instance. This is also referenced in the Apex Developer Guide on the Exceptions in Apex page.

Apex exception emails are limited to 10 emails per hour, per application server. Because this limit isn’t on a per-org basis, email delivery to a particular org can be unreliable.

Depending on the type of unhandled exception and the frequency of that exception type being thrown on a given instance, you might intermittently miss out on getting Apex exception emails.

Best Practices for Surfacing Apex Exceptions in Managed Packages

The recommended course of action for ISV partners is to use AppExchange App Analytics to surface exceptions from within managed packages. To do this, filter your package usage logs by the log_record_type value of ApexUnexpectedException.

To learn more about AppExchange App Analytics, check out the AppExchange Partner Intelligence Basics module on Trailhead.

  • 2
    You rock Vivek! Aug 30, 2022 at 8:13
  • 1
    Thanks, @RobertSösemann! Sorry it took so long for me to get back to you on this. Aug 30, 2022 at 14:52

Apex Error Email for Unlocked Packages were introduced in Winter 21


Hence they should be supported. The CLI docs and release notes mention that an active devhub user must be designated but don't mention if all devhub orgs support these emails.

  • Exactelly that is the documentation I also mention in my question. Should work for Unlocked and Managed 2GP. Mar 3, 2022 at 9:40

You must log in to answer this question.

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