2014-01-13 33 views
0

我希望在更新APEX for salesforce後創建可以接觸聯繫人並在聯繫人字段被選中時重新創建爲潛在客戶的潛在客戶。任何幫助,將不勝感激。Salesforce Apex - 用於創建新潛在客戶的現有聯繫人

是的,所以我認爲我需要列出一些需要轉化爲潛在客戶的聯繫人。我忘記了從聯繫人中獲取字段的格式,所以我可以將它們映射到主角。

public void createLead_Update(List<Contact> oldContacts, List<Contact> newContacts) { 

System.debug('createLead_Update: entering trigger'); 

List<ID> createNewLead = new List<ID>(); 
Lead lead = new Lead(); 
Contact aContact = newContacts[i]; 


for (integer i=0; i<newContacts.size(); i++) { 
// find contacts where the create lead checkbox is checked. 
// on update, we care if the value is changed 
Contact newValues = newContacts[i]; 
Contact oldValues = oldContacts[i]; 
if (newValues.createlead__c != oldValues.createlead__c) { 
createNewLead.add(new Lead(
lead.firstName = aContact.firstName)); 
} 
insert new lead 
} 
    System.debug('createLead_Update: exiting trigger'); 

    } 
+0

你有你自己嘗試新鮮事物? –

+0

@ChrisLava看看我在這裏有什麼。我如何才能將符合要求的聯繫人放入單個列表並一次上傳? – Rich

回答

2
List<Lead> newLeadsList= new List<Lead>(); 
for (integer i=0; i<newContacts.size(); i++) { 
    if (newContacts[i].createlead__c != oldContacts[i].createlead__c && newContacts[i].createlead__c) { 
     newLeadsList.add(new Lead(lead.firstName = newContacts[i].firstName)); 
     } 
} 
insert newLeadsList; 
相關問題