You need to sign in to do that
Don't have an account?
Kingslee Velu 5
Lead Duplicate Check using Territory Fields
Write an apex method called (leadDuplicateCheck) that will validate if a collection of new leads would create duplicates in the system and returns segregated lists in a map
(True: list of non-duplicates & False: list of duplicates). A duplicate lead is defined as same Email, Territory__r.Region__c (text) and Company (text)
//Code Snippet to get you started
List<Lead> newleads = getNewLeads();
Map<Boolean, List<Lead>> leadResults = leadDuplicateCheck(newLeads)
Below code, snippet throws an error . Please advise how we can write code for the above scenario. Thanks.
Incorrect Code Snippet :
Public List<Lead> searchLeads(){
List<Lead> searchLeads = [SELECT Email,Company, Status from Lead order by CreatedDate desc Limit 10];
System.debug(searchLeads);
return searchLeads;
}
public Map<Boolean, List<Lead>> leadDuplicateCheck(newleadvalues){
Map<Boolean, List<Lead>> nodup = new Map<Boolean, List<Lead>>();
nodup.put(True, [SELECT Email,Company from Lead group by Email,Company having count(Id) > 1]);
nodup.put(True, [SELECT Email,Company from Lead group by Email,Company having count(Id) = 1]);
return nodup;
}
(True: list of non-duplicates & False: list of duplicates). A duplicate lead is defined as same Email, Territory__r.Region__c (text) and Company (text)
//Code Snippet to get you started
List<Lead> newleads = getNewLeads();
Map<Boolean, List<Lead>> leadResults = leadDuplicateCheck(newLeads)
Below code, snippet throws an error . Please advise how we can write code for the above scenario. Thanks.
Incorrect Code Snippet :
Public List<Lead> searchLeads(){
List<Lead> searchLeads = [SELECT Email,Company, Status from Lead order by CreatedDate desc Limit 10];
System.debug(searchLeads);
return searchLeads;
}
public Map<Boolean, List<Lead>> leadDuplicateCheck(newleadvalues){
Map<Boolean, List<Lead>> nodup = new Map<Boolean, List<Lead>>();
nodup.put(True, [SELECT Email,Company from Lead group by Email,Company having count(Id) > 1]);
nodup.put(True, [SELECT Email,Company from Lead group by Email,Company having count(Id) = 1]);
return nodup;
}