+ Start a Discussion
Rahul H 4Rahul H 4 

duplicate query

Pls help to write to query duplicate contacts in Salesforce
i wrote the query however it doesnt seem to work :(

Select Count(ID), Name From Contact Group BY Name Having Count(ID) > 1
NagendraNagendra (Salesforce Developers) 
Hi Rahul,

You will run into limits depending on how big the object is but here is the aggregate query that will work to a point:

Please give a try with below piece of code in the developer console.
List<AggregateResult> con=[SELECT Name, count(Id) FROM Contact GROUP BY Name HAVING count(Id)>1];
for(AggregateResult aggres : acc)
System.debug('Finding duplicate names'+aggres);

Then you will have to process the results to do another query to get the ids of the records.

You will have to do this in several steps to get to your final destination.

Hope this helps.

Kindly mark this as solved if the reply was helpful.