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
S RAHMATHULLAS RAHMATHULLA 

I have a batch job but it is interrupting due to to bounced emails. Please advise how to handle the bounced emails in batch apex ?

Mahesh DMahesh D
Hi

Please check the sample trigger:
 
trigger trgBouncedEmails on EmailMessage (after insert) {
    List<Id> parentCaseIds = new List<Id>();
    for ( EmailMessage myEmail : trigger.New ) {
        // mail box full bounced email for Financial Review emails
        if ( myEmail.HtmlBody.contains('full') && myEmail.Subject.contains('Financial Review') )
            parentCaseIds.add(myEmail.ParentId);
    }
    Case[] parentCases = [select c.Id from Case c where c.Id in :parentCaseIds];
    for ( Case c : parentCases ) {
        c.Resend_Email_Count__c += 1;  // this will trigger workflow to send the email again
        c.Resend_Email_Time__c = System.now();  // keep track of when it was last retried
    }
    update parentCases;
}

Please look into the below links:

http://stackoverflow.com/questions/11671856/bounce-email-handling-mailbox-full-using-salesforce-triggers

This will provide you an idea for your issue.

Please do let me know if it helps you.

Regards,
Mahesh