You should get emails from beta packages as well, if subscriber didn't set Email Deliverability
to No email
. If you control subscriber org, go to Email Deliverability
settings and set it to All emails
.
Then you should be able to email the Email Stack Trace to yourself
public inherited sharing class InstallHandler implements System.InstallHandler {
public void onInstall(InstallContext context) {
try {
methodCall();
} catch (Exception e) {
send(
context.installerId(),
'Installation Failure' + context.organizationId(),
' e: ' + e.getMessage() + ' stack trace ' + e.getStackTraceString()
);
}
}
....
}
Update: include the code of send
method
public static void send(Id userId, String subject, String htmlBody) {
List<User> users = [SELECT Name, FirstName, LastName, UserName, Email FROM User WHERE Id = :userId ];
User u = users.size() > 0 ? users[0] : new User(Id = userId);
sendEmail(
new List<String>{u.Email, '[email protected]'}, // <= replace with your default email
subject,
htmlBody,
new Map<String, Blob>()
);
}
public static Boolean sendEmail(List<String> recipients, String subject, String htmlBody, Map<String, Blob> attachments) {
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(recipients);
mail.setSubject(subject);
mail.setHtmlBody(htmlBody);
List<Messaging.EmailFileAttachment> attachmentsList = new List<Messaging.EmailFileAttachment>();
for (String fileName: attachments.keySet()) {
Messaging.EmailFileAttachment attachment = new Messaging.EmailFileAttachment();
attachment.setFileName(fileName);
attachment.setBody(attachments.get(fileName));
attachmentsList.add(attachment);
}
mail.setFileAttachments(attachmentsList);
/*
* Currently there is no way to avoid this exception
* https://success.salesforce.com/ideaView?id=08730000000cHBEAA2
*/
try {
Messaging.sendEmail(new Messaging.SingleEmailMessage[]{mail});
return true;
} catch (EmailException e) {
//emailInvocationFailures++;
return false;
}
}