Loading
透過按一下而非程式碼擴充 Salesforce
追蹤已在 Salesforce 內的商機與連絡人的特定資料隱私權偏好設定

追蹤已在 Salesforce 內的商機與連絡人的特定資料隱私權偏好設定

針對已在 Salesforce 內的商機及連絡人,依據個別物件,使用指令檔建立資料隱私權記錄。

必要版本

提供版本:Salesforce Classic 與 Lightning Experience
提供版本:所有版本,包括合作夥伴與客戶社群使用者。

這些指令檔為每個商機及連絡人建立唯一的資料隱私權記錄。請記住,如果您的商機及連絡人已有資料隱私權記錄,此指定檔將會建立重複記錄。

建立連絡人的資料隱私權記錄

建立資料隱私權記錄並在執行此指令檔時,將其連結至已在 Salesforce 內的連絡人。

global class CreateIndividualFromContact implements Database.Batchable<sObject> {
    global Database.Querylocator start(Database.BatchableContext BC) {
       //Query to fetch contacts that don't have Individual created. You may modify the query to add custom fields  
       //Please add  "IsPersonAccount = false" condition to below query to exclude person accounts
       return Database.getQueryLocator('Select FirstName, LastName, Salutation from Contact where IndividualId = NULL');
    }
    
    global void execute(Database.BatchableContext BC, List<Contact> contactList) { 
        Map<Id, Individual> individualRecordsToCreate = new Map<Id, Individual>();
        for(Contact con : contactList) {
            individualRecordsToCreate.put(con.Id, new Individual(FirstName = con.FirstName, LastName = con.LastName, Salutation=con.Salutation));
        }
        insert individualRecordsToCreate.values();
        for(Contact con : contactList) {
            con.IndividualId = individualRecordsToCreate.get(con.Id).Id;
        }
        update contactList;
    }
    
    global void finish(Database.BatchableContext BC) {}
   
}

建立商機的資料隱私權記錄

建立資料隱私權記錄並在執行此指令檔時,將其連結至已在 Salesforce 內的商機。

global class CreateIndividualFromLead implements Database.Batchable<sObject> {

    global Database.Querylocator start(Database.BatchableContext BC) {
       //Query to fetch non-converted Leads that don't have Individual created. You may modify the query to add custom fields  
       return Database.getQueryLocator('Select FirstName, LastName, Salutation from Lead where IsConverted = false and IndividualId = NULL');
    }
    
    global void execute(Database.BatchableContext BC, List<Lead> leadList) { 
        Map<Id, Individual> individualRecordsToCreate = new Map<Id, Individual>();
        for(Lead l : leadList) {
            individualRecordsToCreate.put(l.Id, new Individual(FirstName = l.FirstName, LastName = l.LastName, Salutation=l.Salutation));
        }
        insert individualRecordsToCreate.values();
        for(Lead l : leadList) {
            l.IndividualId = individualRecordsToCreate.get(l.Id).Id;
        }
        update leadList;
    }
    
    global void finish(Database.BatchableContext BC) {}   
}
 
正在載入
Salesforce Help | Article