0

I have a custom object called connector in that I have a field called connectornumber I want to find the duplicates for connectornumber by using SOQL query can any one help on this ..

5

Try this. Run this query

SELECT Connectornumber__c, count(id) NrOfRecords 
FROM Connector__c 
GROUP BY ConnectorNumber__c
HAVING count(id) > 1

All the records that return are duplicated.

PS: I've just updated this post. The earlier one did not have the having clause.

6
  • 2
    You can even use HAVING in this case: HAVING COUNT(Id) > 1.
    – sfdcfox
    Mar 14 '16 at 3:40
  • Goodness, I didn't even know we had having. Have to brush up on aggregate soql. Updated my post. Mar 14 '16 at 4:32
  • I thought about that and almost commented but...don't you want count(Id) > 0, which will be true for every returned result?
    – Adrian Larson
    Mar 14 '16 at 16:00
  • If I only want to return duplicates, >1 is the right clause. Mar 14 '16 at 16:01
  • I guess it depends on the context. If you are in an insert trigger, you are looking for any existing matches. If you are looking for existing duplicates, you want multiple matches.
    – Adrian Larson
    Mar 14 '16 at 16:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.