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
Akhil R NathAkhil R Nath 

Hello Everyone, I have a requirement to find duplicates of leads in Salesforce by Apex. Can anyone help with me example code?

GulshanRajGulshanRaj
You can use something like this
Lead leadRecord = [Select id from Lead];

List<Id>  idList = new List<Id>();
idList.add(leadRecord.id);

if (Datacloud.FindDuplicatesByIds.​findDuplicatesByIds(idList).size() ​> 0) {
System.debug('Found duplicates');
}

Please make sure you have duplicate rule aligned for lead object.

For more information checkout https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_class_Datacloud_FindDuplicatesByIds.htm



Thanks
Gulshan Raj