1

私は重複除外ツールを使用する従来の方法を調べてきましたが、私はマルチ アライアンスの組織で働いているため、実際にはデータベースのセグメントを調べる必要があるときに、重複除外ツールはデータベース全体を調べます。独自の重複除外ツールを作成してみます。

これまでのところ、次の apex を作成しました。apex は現在、リードの会社名を調べ、データベース内の別の会社名と完全に一致する場合、ユーザーに「別の新しいリードには同じ会社名があります」というエラー メッセージを提供します。</p>

会社名が正確であればこれは素晴らしいことですが、もっと柔軟にする必要があります。

たとえば、「Burger King Limited」が 2012 年に作成されたリードであり、売り手が 2013 年に「Burger King 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.');
        }
    }
}
4

0 に答える 0