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
Priyanka DumkaPriyanka Dumka 

apex for below scenario : We have received list of duplicates and from that list we want to remove the duplicate on basis of name, email and phone number ?

apex for below scenario :

We have received list of duplicates and from that list we want to remove the duplicate on basis of name,email and phone number ? 



 
GulshanRajGulshanRaj
Hi Priyanka,

Why don't you try duplicate rules and restrict duplicate records from the very first door? Checkout duplicate rule article here: https://help.salesforce.com/s/articleView?id=sf.duplicate_rules_map_of_reference.htm&type=5

Best Regards
Gulshan Raj
SubratSubrat (Salesforce Developers) 
Hello Priyanka ,

As per your ask , you want to prevent duplicates records based on multiple fields , so for this I would request you to go through this reference article once for your understanding -> https://www.mstsolutions.com/technical/preventing-duplicate-records-based-on-multiple-fields-in-salesforce/

Also attaching reference for complete guide of duplicate Rules ->https://www.salesforceben.com/salesforce-duplicate-rules/

If it helps please mark this as Best Answer.
Thank you.





 
prashant rishi 6prashant rishi 6
Hi Priyanka ,
could u please scenario how u are getting the List of duplicates 
What u can do is create map
Like Map<String,opportunity> oppMap
it will be like this
for(opportunity opp : [Select Id,Name,phonenumber,Email from opportunity]){
String key = opp.Name + '-' + opp.Email + '-' + opp.phonenumber;
oppMap,put(key,opp);
}
In this oppMap u will add in the keyset which will be always unique 
so next time similar value came it will not add in the map because u already have those values in Map.
Hope it clears your query.