function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
PhoenixRising12PhoenixRising12 

Trying to Tag Duplicate Records with Boolean Field in Anonymous window

I'm trying to query duplicate accounts through Anonymous Window. I'm doing this through querying the Aggregate result object.
I'm trying to get the Account Name and then compare it. In the debug log, I'm trying to query those duplicate accounts that match the Account Name in the AggregateResult in acctList2 but in the Debug Log it says 0. How should I approach this? 
 
AggregateResult[] Aggies123 = [select Name, count(Id) from Account WHERE RecordType.Name = 'Partners' GROUP by Name HAVING COUNT(Id)>1];
String AccountNaming;
List<Account> accList2 = new List<Account>();
List<Account> accList3 = new List<Account>();
for (AggregateResult Agg1 : Aggies123){

AccountNaming = String.valueOf(Agg1.get('Name'));                                             
}

AccountNaming = '%' + AccountNaming + '%';
accList2 = [SELECT Id, Name FROM Account WHERE Name LIKE :AccountNaming];
System.debug(accList2.size());

for(Account A1 : accList2){
    
    A1.PotentialDuplicate__c = TRUE;
    accList3.add(A1);
    
    
}

 
PriyaPriya (Salesforce Developers) 

Hey,

You can take the reference from this code to find the matches :- 

https://developer.salesforce.com/forums/?id=906F0000000fyhvIAA

Regards,

Priya Ranjan