0

multiple records might have the external id. I want to Query all the duplicate Records ,I want to know all the Records which is having same external Id

How can I perform this query?

The Answer is:

SELECT External__c, count(Id) records FROM MyObject__c
GROUP BY External__c HAVING count(Id) > 1

If you are open to using Apex, you can generate a Set based on the above. If your volume is low enough, you can do it all in one go:

Set<String> externalIds = new Set<String>();
for (AggregateResult aggregate : [
    SELECT External__c FROM MyObject__c
    GROUP BY External__c HAVING count(Id) > 1
]) externalIds.add((String)aggregate.get('External__c'));

List<MyObject__c> duplicates = [
    SELECT Id, External__c FROM MyObject__c
    WHERE External IN :externalIds
];

I am Having Large Number of Records,How to Query? then I want to know all records which is having same External Id,Guide Me for the Answer

  • why don't you use SELECT External__c, count(Id) records FROM MyObject__c GROUP BY External__c HAVING count(External__c ) > 1 – Tushar Sharma Sep 15 '16 at 6:42
  • @TusharSharma No records is Displaying to Me – SFDC Sep 15 '16 at 6:51
  • @TusharSharma I want to display all the Recordids which have the same external Id for External_c field How – SFDC Sep 15 '16 at 6:56
  • I may have Different Recordtypes that may be caused the Problem ah? @TusharSharma – SFDC Sep 15 '16 at 7:04
  • @eric ,@adrian Larson,@tushar sharma i am created the field as set as external Id and now i am changing the field to set as unique record identifier, i am not able to change,for that i want to query all the duplicate records with different Record id ,How to Query ,The above query displaying count field only,i want all Record ids,which have same external id field – SFDC Sep 15 '16 at 7:49

Browse other questions tagged or ask your own question.