Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8289593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:32:32+00:00 2026-06-08T12:32:32+00:00

I’m trying to solve the bouncing email issue based on Mail box full by

  • 0

I’m trying to solve the bouncing email issue based on “Mail box full” by creating a trigger that resends the message if the message contains “mail box full”.

The issue I’m facing is that I need to limit the number of resend to 3 times.
What I have now keeps resending the email as soon as a bounced email is received.

My trigger is

trigger trgBouncedEmails on EmailMessage (after insert) {

  for(EmailMessage myEmail: trigger.New) {


    //mail box full bounced email 
    if (myEmail.HtmlBody.contains('full'))
    {

        Case[] parentCase = [Select c.Id from Case c where c.Id =: myEmail.ParentId];


         if (myEmail.Subject.contains('Financial Review'))
                parentCase[0].Resend_Email_Send__c = true;  // this will trigger a workflow to send the email again.

          Update parentCase;
              }
      }
}

How can I limit the resending, is there a way I can set a wait time before I do the “Update parentCase”

Is there a better way to solve this issue, knowing that I have different types of emails, each one has a different template and a different purpose.

EDIT
The system should automatically re-send the email 3 times in the frequency of 24hours, and then stops resending after 24hrs. My trigger keeps resending indefinitely and I’m trying to find a way to put a wait so it can only send 3 times in 24hrs period, like once every 8hrs.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T12:32:34+00:00Added an answer on June 8, 2026 at 12:32 pm

    @grigriforce beat me to the punch – I would also suggest using a field to count the number of retries, rather than a simple boolean value. Here’s a “bulkified” trigger with essentially the same logic as the one you posted:

    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;
    }
    

    Update to space emails out evenly over a 24-hour period:

    Rework your workflow to make sure it has been 8 hours since Resend_Email_Time__c was last set, and then schedule an Apex job to run every hour to pick up eligible Cases that need to have their emails resent, and call update on them to make sure the workflow doesn’t go too long without firing:

    global class ResendCaseEmails implements Schedulable {
        global void execute(SchedulableContext sc) {
            Contact[] cs = [select id, Resend_Email_Count__c, Resend_Email_Time__c from Contact where Resend_Email_Count__c < 4];
            List<Contact> ups = new List<Contact>();
            for ( Contact c : cs ) {
                if ( c.Resend_Email_Time__c != null && c.Resend_Email_Time__c.addHours(8) < System.now() )
                    ups.add(c);
            }
            update ups;
        }
    }
    

    **note that it’s not a best practice to have this code in the class that implements Schedulable – this code would ideally be in another class that is called by the ResendCaseEmails class.

    You can schedule this job to run once an hour by calling this code from the developer console:

    ResendCaseEmails sched = new ResendCaseEmails();
    String cron = '0 0 * * * ?';
    System.schedule('Resend Case Email Job', cron, sched);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am doing a simple coin flipping experiment for class that involves flipping a
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.