Hello friends, In this post, I will show an example that helps you to find duplicate record on standard or custom objects in salesforce. This query can be used to find related object duplicate records also. So without wasting time let's get started,

Get duplicate records using SOQL

1. Suppose you have to find those account records, who have same name so for that use following soql query.

 Select count(ID), Name From Account GROUP BY Name Having Count(Name) > 1

Output:


2. Suppose you have to find account related duplicate contact records whose language is english, for that use the following soql query.
 Select count(ID), AccountId From Contact where Languages__c='English' GROUP BY AccountId Having Count(AccountId) > 1

Output:


In both scenarios, you can see the count of records, that clearly shows that objects has duplicate records. This type of soql query will help you audit records on salesforce object .

Hope you like this post, for any feedback or suggestions please feel free to comment. I would appreciate your feedback and suggestions.
Thank you.