我看过使用去欺骗工具,但是传统的方法,因为我工作的一个组织,它是多盟去欺骗工具着眼于整个数据库,当我真正需要看看数据库的部分工作,所以我已经决定尝试创建自己去欺骗工具。
到目前为止,我已经创建了下面的顶点。 顶点目前着眼于对铅的公司名称以及是否有与数据库中其他公司的名称完全匹配它为用户提供了错误信息“的又一新铅具有相同的公司名称”
这是伟大的,如果公司名称是确切的,但我需要它更加灵活。
例如,如果“汉堡王有限公司”是在2012年创造了领先优势,卖方已决定建立一个在2013年所谓的“汉堡王LTD”铅这是该公司为这是在2012年创建的铅一样。
我想建立一个模糊逻辑,着眼于新的领导,如果有轻微的相似之处则无视新领导
Trigger DuplicateLeadPreventer on Lead
(before insert, before update) {
//Get map of record types we care about from Custom Setting
Map<String, Manage_Lead_Dupes_C__c> leadrtmap = Manage_Lead_Dupes_C__c.getAll();
//Since only certain leads will match, put them in a separate list
List<Lead> LeadstoProcess = new List<Lead> ();
//Company to Lead Map
Map<String, Lead> leadMap = new Map<String, Lead>();
for (Lead lead : Trigger.new) {
//Only process for Leads in our RecordTypeMap
if (leadrtmap.keyset().contains(lead.RecordTypeId) ) {
// Make sure we don't treat an Company name that
// isn't changing during an update as a duplicate.
if (
(lead.company != null) &&
(Trigger.isInsert ||
(lead.company != Trigger.oldMap.get(lead.Id).company))
)
{
// Make sure another new lead isn't also a duplicate
if (leadMap.containsKey(lead.company)) {
lead.company.addError('Another new lead has the '
+ 'same company name.');
} else {
leadMap.put(lead.company , lead);
LeadstoProcess.add(lead);
}
}
} //end RT If Check
} //End Loop
/*
Using a single database query, find all the leads in
the database that have the same company address as any
of the leads being inserted or updated.
*/
Set<String> ExistingCompanies = new Set<String> ();
for (Lead l: [Select Id, Company from Lead WHERE Company IN :leadMap.keyset()
AND RecordTypeId IN :leadrtmap.keyset()]) {
ExistingCompanies.add(l.Company);
}
//Now loop through leads to process, since we should only loop if matches
for (Lead l : LeadstoProcess) {
if (ExistingCompanies.contains(l.company) ) {
l.company.addError('A lead with this company '
+ 'name already exists.');
}
}
}