Scenario The data-quality team is cleaning up the CRM. Several Contacts share the same email address, which causes duplicate outreach and failed merges. Before merging anything they want a list of the email addresses that are used more than once, and how often.
Task
Write one SOQL query on Contact that:
Email is null).Email.Email ascending.Expected output
One row per duplicated email with two columns: Email and dupes (the number of Contacts that use it).
Example
Contacts: three use shared@example.com, two use pair@example.com, one uses solo@example.com, and two have no email.
| dupes | |
|---|---|
| shared@example.com | 3 |
| pair@example.com | 2 |
solo@example.com is dropped because it is used only once, and the Contacts with no email are ignored.
Use one aggregate query on Contact. Exclude null emails with WHERE, group by Email, and keep groups with more than one Contact using HAVING. Alias the count as dupes. Order by dupes descending, then Email ascending.
2 row(s), order checked
| # | dupes | |
|---|---|---|
| 1 | shared@example.com | 12 |
| 2 | pair@example.com | 2 |