Salesforce Apex - 用于创建新潜在客户的现有联系人

时间:2014-01-13 19:40:12

标签: salesforce contact apex lead

我想在更新APEX for salesforce之后创建,当联系人的字段选中为true时,可以接受联系并将其重新创建为潜在客户。任何帮助将不胜感激。

是的所以我想我需要列出需要转移到潜在客户的联系人列表。我忘记了从联系人那里抓取字段的格式,所以我可以将它们映射到导联中。

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');

    }

1 个答案:

答案 0 :(得分: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;