1

i have been trying to update the existed lead contacts ,but it is not updating.can anyone help me on this please?

Trigger AutoConverter on Lead (after insert) {
     LeadStatus convertStatus = [select MasterLabel from LeadStatus where IsConverted = true limit 1];
     List<Database.LeadConvert> lc1 = new List<Database.LeadConvert>();

     for (Lead lead: Trigger.new) {
          if (!lead.isConverted && lead.LeadSource == 'web') {
               Database.LeadConvert lc = new Database.LeadConvert();
               String oppName = lead.Name;

               lc.setLeadId(lead.Id);
               lc.setOpportunityName(oppName);
               lc.setConvertedStatus(convertStatus.MasterLabel);

               lc1.add(lc);
          }
     }

     if (!lc1.isEmpty()) {
          List<Database.LeadConvertResult> lcr = Database.convertLead(lc1);
     }
}

after that I am feeling tricky, can anyone suggest for the answer,any help appreciated thanks

2
  • only you can update the contacts, after lead is converted, so use after update and query the contact which you want and update it @chakri
    – SFDC
    Apr 20, 2017 at 7:37
  • first modify the after insert trigger to find the correct account and contact
    – SFDC
    Apr 20, 2017 at 9:55

1 Answer 1

1

For Updating use this code

trigger updateRelatedRecords on Lead (after update) {
  Map<Id, Account> accounts = new Map<Id, Account>();
  Map<Id, Contact> contacts = new Map<Id, Contact>();
  Map<Id, Opportunity> opps = new Map<Id, Opportunity>();
  for(Lead record: Trigger.new) {
    if(record.IsConverted) {
      accounts.put(record.ConvertedAccountId, new Account(Id=record.ConvertedAccountId, Phone=record.Phone));
      contacts.put(record.ConvertedContactId, new Contact(Id=record.ConvertedContactId, Phone=record.Phone));
     opps.put(record.ConvertedOpportunityId, new Opportunity(Id=record.ConvertedOpportunityId, name=record.Name));
    }
  }
  accounts.remove(null);
  contacts.remove(null);
  opps.remove(null);
  update accounts.values();
  update contacts.values();
  update opps.values();
}
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .