每當聯繫人記錄上的賬戶發生更改時,聯繫人應轉換回潛在客戶。我有從接觸到領導的映射領域。這可能嗎 ?如何實現這一目標?刪除聯繫人中的賬戶名稱後,應將「聯繫人」記錄轉換回「LEAD」記錄
我試圖通過編寫一個觸發器來做到這一點:
trigger insertLead on Contact (before update,before delete) {
Set<Id> aId = new Set<Id>();
Lead myLead = new Lead();
for (Contact opp : Trigger.new) {
aId.add(opp.AccountId);
List<Account> acc = [select Name from Account where Id in:aId];
List<Contact> con = [select LastName,FirstName from Contact where accountId = :aId];
for(Account a: acc){
myLead.Company = a.Name;
}
for(Contact c: con)
{
myLead.LastName = c.LastName;
myLead.FirstName = c.FirstName;
}
insert myLead;
}
這是錯誤:
Error:Apex trigger insertLead caused an unexpected exception, contact your administrator: insertLead: execution of BeforeUpdate caused by: System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Company]: [Company]: Trigger.insertLead: line 15, column 1