+ 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