Targeted Detection - By Related Object
Before proceeding, make sure you have read the Targeted Detection page, as it provides important context for this section.
Email Scrubber’s Targeted Detection primarily focuses on Case‑based filtering. However, Email Scrubber also supports targeting emails related to any Salesforce object referenced through the email’s RelatedToId (such as Opportunity, Account, or custom objects). This allows you to apply the same retention logic across all business records that email messages may be associated with.
​
Example targeted detection rules
A targeted detection policy might identify emails where:
-
The related Opportunity has been Closed Won for more than 12 months
-
The related Account has been marked Inactive for more than 6 months
-
The related business record meets any lifecycle, compliance, or product‑specific criteria defined by your organization
​
This flexibility allows Email Scrubber to evaluate and archive emails across your full data model—not just Cases.
Configure Declutter Setup Custom Metadata Type
All Email Scrubber processing logic is controlled by the Declutter Setup Custom Metadata Type. Please review the documentation for a complete list of its capabilities.
​
In this example, Email Scrubber is archiving all Email Messages related to an Opportunity where the opportunity was created more than 14 months prior.
​

Reference the Targeted Detection page for all information related to scheduling and archiving the archive process.
Notice
When Email Scrubber archives an EmailMessage, only the primary relationship is preserved.
​​
EmailMessageRelation records (the Who relationships such as Contacts, Leads, and Users referenced in the email) are not retained in the archive object. Any participant‑level context is preserved only to the extent that it exists in the fields copied onto the archive record itself (e.g., raw address strings, header fields, or any metadata your org has chosen to store).
​
As a result:
-
Archived emails will not maintain their original Who‑related associations
-
Multi‑recipient context is not reconstructed in the archive
-
Reporting or compliance processes that rely on EmailMessageRelation data will not have access to those relationships once the email is archived
Optional Configuration: Preserving Parent Relationships in the Archive Object
By default, when Email Scrubber archives an EmailMessage, it stores the original RelatedToId in the archive record’s Archive Related Id field. If you want the archived email to appear as a related list on the parent record (e.g., Opportunity, Account, or a custom object), you must complete an additional configuration step.
​
To surface archived emails directly on their parent records (additional details available):
​
-
Create a Lookup field
-
On your archive object (EmailScrubber__Redundant_EmailMessage_History__c), create a new Lookup field that points to the parent object you want to relate back to (e.g., Opportunity, Account, or a custom object).
-
This field will store the parent record ID.
-
-
Add a new mapping in “History Related To”
-
In Email Scrubber’s configuration, open History Related To mappings.
-
Create a new mapping that links the EmailMessage’s RelatedToId to the new lookup field you created.
-
-
Activate the mapping
-
Once the mapping is active, the Email Scrubber process will automatically populate the lookup field on each archive record during processing.
-
​
When this configuration is enabled:
-
Each archived email will store a direct lookup to its parent record.
-
You can add the archive object as a related list on the parent object’s page layout.
-
This allows users to view archived emails in context, even after the original EmailMessage has been removed.

