Loading

Prevent Case Creation for Bounced or Out-of-Office Emails

Udgivelsesdato: Jun 3, 2026
Beskrivelse

When Email-to-Case is enabled, Salesforce creates a case for every incoming email to your support address, including bounced messages and Out-of-Office (OOO) auto-replies. This can create noise in your case queue and increase manual triage work. To prevent unwanted case creation from these email types, you can use an Apex trigger on the Case object to detect and block these cases before they are inserted. This article provides sample code and guidance to get you started.

Løsning

How It Works

First, configure a unique Case Origin value (for example, Support Email) specifically for cases created by Email-to-Case. This allows the trigger to identify which cases originated from an email and which originated from other channels. The Apex trigger then inspects the Subject field of incoming cases to detect OOO patterns or bounce notifications and takes the appropriate action.

Example Code

The following Apex trigger runs on before insert for the Case object. It detects Email-to-Case cases based on the Origin field and provides a placeholder for your custom logic to block or flag them. Customize the logic inside the if block to match your organizational requirements:

trigger manageEmailCases on Case (before insert) {
for (Case thisCase : trigger.new) {
if (thisCase.Origin == 'Support Email') {
/* Add your logic here.
Example: block cases with OOO subjects
if (thisCase.Subject.contains('OOO')) {
thisCase.addError('Not saving — Out of Office email');
}
*/
}
}
}

What Logic to Add

Customize the logic inside the if block to match your organization's requirements. Common approaches include:

  • Checking for keywords like OOO, Out of Office, Bounced, or Undeliverable in the Subject field.
  • Using thisCase.addError() to block the case from being inserted.
  • Setting a custom field flag (for example, Needs_Review__c = true) to mark the case for manual triage instead of blocking insertion.

Considerations

Hard-coding known Origins or Subjects is one approach, but you also want to avoid accidentally blocking legitimate cases with poorly written logic. Consider making your detection patterns configurable using Custom Metadata Types or Custom Labels so they can be updated without redeploying code. Adjust the logic to account for emails in different languages or variations of Out-of-Office text. It is often safer to flag cases for review rather than block them entirely, especially when you first deploy the trigger.

Vidensartikelnummer

000387850

 
Indlæser
Salesforce Help | Article