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.
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.
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');
}
*/
}
}
}
Customize the logic inside the if block to match your organization's requirements. Common approaches include:
OOO, Out of Office, Bounced, or Undeliverable in the Subject field.thisCase.addError() to block the case from being inserted.Needs_Review__c = true) to mark the case for manual triage instead of blocking insertion.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.
000387850

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.