function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Max H. GoldfarbMax H. Goldfarb 

How can I send an email while using PageReference getContent() method?

I am trying to send an email while using PageReference and the getContent() method which is, only ocassionally, throwing an error (seems like every couple of emails regardless of the frequency). According to the docs, the getContent() method cannot be used in Apex email services.

When I do not invoke any email service my code works as expected 100% of the time, however it seems like when I attempt to send an email in the same context of when I use my getContent() method, an underlying SFDC bug occasionally is throwing the error: "FATAL_ERROR System.VisualforceException: null."

I have tried a lot of workarounds, including future methods, posting chatter feed posts to groups with emails on for every post, using a batch class and sending the email in the finish context, and a few other things but to no avail. I am hoping someone may have some ideas or can help lead me in the right direction. My code is below, thanks!
 
global class emailDeliverabilityStatus implements Schedulable {
    global void execute(SchedulableContext ctx) {
        PageReference pr = new PageReference(Url.getSalesforceBaseUrl().toExternalForm() + '/email-admin/editOrgEmailSettings.apexp');
        Blob statusCheck = pr.getContent();
        Email_Status__c	status = Email_Status__c.getall().values()[0];
        if (statusCheck != null && statusCheck.toString().contains('All email')) {
            status.deliverability_on__c = true;
            status.time_changed__c = system.now();
            List<String> sendTo = status.email_list__c.split(',');
            //Calls future method that sends the email to notify users
            sendEmailDelivNotification.sendEmail(sendTo, status.time_changed__c);
        } else if (statusCheck != null) {
            status.deliverability_on__c = false;
            status.time_changed__c = system.now();
        }
        update status;
    }
}