Salesforce Duplicate Detection Alert
Salesforce action: ExecuteSOSLSearchQuery. Scheduled daily flow runs SOSL searches for potential duplicate Contacts and Leads by name/email patterns, compiles a dedup report, and emails it to the Salesforce admin team.
Provided as-is, without warranty of any kind. Review and test each pattern in a non-production environment before deploying it to live automations. See our Terms.
Overview
CF-234 is an intermediate-level scheduled flow that runs daily SOSL (Salesforce Object Search Language) searches to detect potential duplicate Contacts and Leads by email pattern. It queries recently created Contacts, searches for matching records across both the Contact and Lead objects, compiles a styled HTML dedup report, and emails it to the Salesforce admin team.
Use Case
Sales teams and IT admins need proactive visibility into duplicate records entering Salesforce. Manual dedup checks are time-consuming and error-prone. This flow automates daily scanning of new Contacts, cross-referencing them against existing Contacts and Leads via SOSL email search, and delivers an actionable report so admins can merge or remove duplicates before they cause data quality issues.
Flow Architecture
Daily Recurrence
RecurrenceFires every day at 7:00 AM Eastern Standard Time.
Initialize Variables (4x Parallel)
Initialize variableLoads configurable values from environment variables and initializes working variables: varRecipientEmail (from flowlibs_DuplicateDetectionRecipientEmail), varLookbackHours (from flowlibs_DuplicateDetectionLookbackHours), varDuplicateReportHtml (empty string for HTML row accumulation), and varDuplicateCount (integer counter, initialized to 0).
Compute Cutoff DateTime
ComposeCalculates addHours(utcNow(), mul(int(varLookbackHours), -1)) to determine the lookback window.
Get Recent Contacts
Salesforce - Get items (table_contact)Retrieves recently created Contacts using OData filter CreatedDate ge {cutoff}, ordered by CreatedDate desc, top 100.
For Each Recent Contact
Apply to each (sequential)For each recent contact: runs ExecuteSOSLQuery with SOSL 'FIND {email} IN EMAIL FIELDS RETURNING Contact(Id, Name, Email, CreatedDate), Lead(Id, Name, Email, Company)', filters out the contact's own record by Id, then conditionally appends an HTML table row to varDuplicateReportHtml and increments varDuplicateCount when matches remain.
If varDuplicateCount > 0
If conditionOnly sends a report when at least one potential duplicate was found across the recent contacts.
- Compose Full Report — Builds a CSS-styled HTML report with a KPI banner and the accumulated data table rows.
- Send Duplicate Alert Email — Office 365 Outlook SendEmailV2 sends the report to varRecipientEmail with High importance.
Environment Variables
| Schema name | Type | Default | Description |
|---|---|---|---|
| flowlibs_DuplicateDetectionRecipientEmail | String | admin@your-tenant.onmicrosoft.com | Email address (or distribution list) to receive the daily duplicate detection report. |
| flowlibs_DuplicateDetectionLookbackHours | String | 24 | Number of hours to look back when querying recently created Contacts. |
Connectors & Connections
| Connector | API name | Actions used |
|---|---|---|
| Salesforce | shared_salesforce | GetItems_table_contact ExecuteSOSLQuery |
| Office 365 Outlook | shared_office365 | SendEmailV2 |
Note — All connections are referenced as solution connection references; the flow is portable between environments as long as a connection is mapped at import time.
Customization Guide
Almost every realistic variant of this flow can be implemented by changing environment variable values. A few cases require small edits inside the flow definition — those are called out explicitly below.
- Update environment variables
- Set flowlibs_DuplicateDetectionRecipientEmail to your Salesforce admin team's email or distribution list, and flowlibs_DuplicateDetectionLookbackHours to your preferred scanning window (default 24 hours).
- Authorize connections
- Open the flow in the designer and authorize the Salesforce and Office 365 Outlook connections with appropriate credentials.
- Adjust SOSL scope
- The flow searches across Contact and Lead objects by email. To expand the search to additional objects (e.g., Account), modify the SOSL RETURNING clause in the Search For Duplicates By Email action.
- Turn On the flow
- After authorizing connections, turn the flow on. It will run daily at 7 AM Eastern and email a report only when duplicates are detected.
Key Expressions
The flow is intentionally light on Power Fx / WDL gymnastics — the heaviest expressions are the branch-name concatenation and the approval outcome check. They are listed below in the order they appear in the flow.
EXPR.01Cutoff calculation
Computes the dynamic lookback window from the configurable hours variable.
EXPR.02OData filter for recent Contacts
ISO 8601 datetime filter used in the Salesforce Get items action.
EXPR.03SOSL query (per contact)
Dynamic per-contact SOSL search across Contact and Lead objects by email.
EXPR.04Self-exclusion filter
Removes the source contact from its own SOSL search results before counting matches.
EXPR.05Match count
Counts potential duplicates after self-exclusion to drive the report condition.
Comments
Sign in to join the conversation.
Sign inNo comments yet. Be the first to share your experience with this flow.