Skip to content
Skip to content
SalesforceFox

SalesforceFox

Easy way Learning & Exploring Salesforce !

  • Home
  • All Blogs
  • How To
  • Tips & Tricks
  • Salesforce Quiz
  • Resources
  • About
How to Find duplicate Records in Salesforce

How to Find Duplicate Records in Salesforce

Piyush LakhaniJanuary 30, 2025January 30, 2025

Having duplicate records in your salesforce org can cause serious issue not limited to inaccurate reporting and lost opportunities. It’s crucial to identify and remove them for business-critical reasons. In this post, we will see how to find duplicate records.

Table of Contents
[Open][Close]
  • Using SOQL to find duplicate records
  • Few more Examples
  • Conclusion

Using SOQL to find duplicate records

Simple and easiest way to find duplicate records in salesforce is to use SOQL. You would typically want to identify records that have identical values in one or more fields in records. For example, you’re tasked to find duplicate Contact by its Phone number.

So in this case you can use GROUP BY clause of SOQL. This clause can be used to aggregate records by specific fields, and you can then use the HAVING clause to filter out groups that contain only one record, leaving you with those that have duplicates. Let’s in practice for above Lead example,

SELECT Phone, Count(Id)
FROM Contact
GROUP BY Phone
HAVING Count(Id)>1

First part of query from Line 1 to 3, It will Select Phone field and counts the number of contact records for each of phone numbers.

now second part line 4, using HAVING clause along with group by you can filter all aggregated records so here filter Count(Id)>1, will give you all records where phone numbers occurs more than once among all records.

Read more on use of Group by in SOQL Here

Few more Examples

1. Find duplicate leads by its Name and LeadSource

SELECT Name, LeadSource Count(Id)
FROM Lead
GROUP BY Name, LeadSource
HAVING Count(Id)>1

This will give you number of lead records for each duplicated Name and LeadSource.

2. Find duplicate Opportunities by Name and AccountId

SELECT Name, AccountId Count(Id)
FROM Opportunity
GROUP BY Name, AccountId
HAVING Count(Id)>1

This will give you number of opportunity records for each duplicated Name and its Account.

Conclusion

Using these SOQL queries with GROUP BY & HAVING clause, you can easily find duplicate records in Salesforce based on fields like Name, Email, AccountId, and custom fields. Identifying duplicates is the first step toward maintaining clean, accurate data in your Salesforce environment.

Share this Now :

Related Posts:

  • How to Secure Your Salesforce Org
    How to Secure Your Salesforce Org: First Steps…
  • Get started with Salesforce
    How to get started with Salesforce - for Beginners
  • How To Zip & UnZip Files In Salesforce
    How to Zip & Unzip files Natively in Salesforce: Use…
  • How To Use Flow Approval Process instead of Classic Approval Process
    How to use Flow Approval Process In Salesforce ?
How To, SOQL

Post navigation

Previous: Tips to Improve Report Performance in Salesforce
Next: Mastering SOLID Principles in Apex: Write Cleaner, Scalable and Maintainable Code for Salesforce

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Get Weekly Salesforce Quiz

Categories

  • Admin (8)
  • Apex (6)
  • Automation (7)
  • Best Practices (6)
  • Flow (5)
  • LWC (4)
  • Security (1)
  • SOQL (1)
  • Trigger (1)
  • Uncategorized (1)

Recent Posts

  • User Access Policy in Salesforce : The Smartest way to Automate User Management Jobs
  • Display Apex-Defined Collection Data directly into Screen Flow Data Table
  • How to Secure Your Salesforce Org: First Steps Against Cyber Attacks and Social Engineering
  • Make Salesforce Screen flows more Interactive with Toast Messages
  • How to Zip & Unzip files Natively in Salesforce: Use This Ready-to-Use ZIP Utility

Tags

Admin Apex Aura Component Automation Best Practices Development Email Alerts Flow Flow Approval Process How To Lightning Experience LWC Reports Scheduled Jobs Security SOQL Tips Trigger User Management

Archives

  • November 2025 (1)
  • October 2025 (1)
  • August 2025 (1)
  • July 2025 (1)
  • June 2025 (2)
  • May 2025 (1)
  • April 2025 (2)
  • March 2025 (2)
  • January 2025 (2)
  • December 2024 (1)
  • October 2024 (1)
  • September 2024 (1)
  • August 2024 (1)
  • June 2024 (1)
  • April 2024 (1)
  • March 2024 (1)
  • October 2023 (1)
  • Linkedin
  • Youtube
  • Privacy Policy
  • Terms of Use
  • Contact
Theme: BlockWP by Candid Themes.
© 2023-2026 | SalesforceFox.com