+ Start a Discussion

Apex Email on Trigger not sending due to "Single email queued for send (pending commit)"

I wrote an update trigger (tried both before and after update) on Case that checks some conditions and sends an email to the Case contact if they are true.

PROBLEM:  In the system logs, I’m seeing “Single email queued for send (pending commit)” and the email isn't sending.

Answers to obvious questions: I'm not seeing any errors in the logs, the trigger is firing okay and the field update I am doing in the trigger is happening.

Does anyone know why the email is not sending?  Here's the code:

trigger CaseClosedEmail on Case (before update) {
    List<Contact> cons;
    List<EmailTemplate> et = [Select Id From EmailTemplate Where DeveloperName ='CustomerSupportClose'];
    Set<Id> conIds = new Set<Id>();
    Map<Id, String> conInfo = new Map<Id, String>();
    //Put contactId of each case in a set so we can query the contacts
    for(Case c : trigger.new){
    //Get all the contacts of closed cases
    cons = [Select Id, Email From Contact Where Id in :conIds];
    //Put those contact IDs and their emails in a map
    if(cons.size() > 0 ){
        for(Contact c : cons){
            conInfo.put(c.Id, c.Email);

    for(Case c: trigger.new){
        if(c.Status == 'Closed'
        && conInfo.containsKey(c.ContactId)
        && et.size() == 1
        && c.Con_Close_Email_Sent__c == false){

            // Create a new single email message object
            // that will send out a single email to the addresses in the To list.
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            // Strings to hold the email addresses to which we are sending the email.
            String[] toAddresses = new String[] {conInfo.get(c.ContactId)};
            // Assign the addresses for the To and CC lists to the mail object.
            // Specify the address used when the recipients reply to the email.
            // Specify the name used as the display name.
            mail.setSenderDisplayName('Genome Quest Support');
            // Specify the subject line for your email address.
            //mail.setSubject('Your case ' + c.Id + 'has been closed');
            // Don't append the salesforce.com email signature to the email.
            //The IDs to ensure that merge fields in the template contain the correct data.
            // Specify the template content of the email.
            // Send the email you have created.
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
            c.Con_Close_Email_Sent__c = true;

I also just tried to send an email on a before update trigger on Account, it gave the same "pending commit" message in the logs and then the email sent fine.  So any idea why this is happening on Case?
Looks like the issue was SFDC didn't like the subject line in the email template.  This is the subject "Your case {!Case.CaseNumber} has been closed. {!Case.Thread_Id}" It doesn't seem to have any obvious spam words?  Anyway, I'll play with it.

. I am having the same trouble. Was it the subject after all?



I am facing the same issue, any solution to this?