1

I need to merge duplicate Account, for that I loop through DuplicateRecordItem and put DuplicateRecordSetId and Set into a map. Now I looped through duplicateRecordset and try to merge account but getting this error, (COMPILE ERROR: Invalid type for duplicate records).

Map<Id, Set<Id>> mapDuplicateRecordItem =  new Map<Id, Set<Id>>();

for(DuplicateRecordItem drI : [SELECT Id,RecordId, DuplicateRecordSetId FROM DuplicateRecordItem where DuplicateRecordSetId In : mapDuplicateRecordSet.keyset()]){

    if(!mapDuplicateRecordItem.containskey(drI.DuplicateRecordSetId)){
        mapDuplicateRecordItem.put(drI.DuplicateRecordSetId, new Set<Id>{drI.RecordId}); 
    }
    else{
        mapDuplicateRecordItem.get(drI.DuplicateRecordSetId).add(drI.RecordId); 
    }
} 

for(DuplicateRecordSet dr : [SELECT Id FROM DuplicateRecordSet where Id IN : mapDuplicateRecordItem.keyset()]){

    Set<Id>  setaccId =  mapDuplicateRecordItem.get(dr.Id);

    for(Account acc : [SELECT Id, name,BillingCountry, BillingState, ownerId FROM Account where ID In : setaccId]){ 

        //setacc.remove(acc.Id);
        Account accnt = new Account(ID = acc.id)
        if(!setaccId.contains(acc.Id)){ 
            merge acc setaccId; 
        }  
    }  
} 

How to merge Account in this way ? or suggest any other idea Please.

1

You'll need to convert your Set<Id> to a List<Id>. You also need to make sure that the list contains no more than two duplicates at a time. See Merging Records for acceptable forms. Basically, you can provide an SObject, List<SObject>, Id, or List<Id> as the second parameter to merge.

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.