• Israel Silvestre 9
  • NEWBIE
  • 10 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
Hi All,

I'm quite new into development and I was looking for answer. We need to have a particular picklist field(Lead_Status__c) in Contact be updated to "Qualified" after the lead was converted with an Opportunity (during conversion of the lead, optionally adding new Opportunity). 

We tried to use workflow and process builder but it end up as "false" in the debug log, so the option is via apex. I manage to do some search in sites and found this code:
 
Trigger Lead on Lead (after update) {

    if (Trigger.isAfter) {

        if (Trigger.isUpdate) { 

            Map<ID,ID> oppToContact = new Map<ID,ID>(); 

            for (Lead ld : Trigger.new) {
                if(ld.isConverted && trigger.oldMap.get(ld.id).isConverted) continue; //only process newly converted leads

                // Find all converted Leads with Opportunitiy and add ConvertedOpportunityId to setConvertedOppIds
                if (ld.ConvertedOpportunityId != null && ld.ConvertedContactId != null){                    
                    oppToContact.put(ld.ConvertedOpportunityId,ld.ConvertedContactID);  

                }

            }
I might need to find the additional code to add here to update the Lead Status in Contact if this particular record was converted from a lead and with added opportunity upon conversion, can anyone please help me on this code? Im quite new in this development and would really like to explore further. Please see image below of the supposed field to update when the Lead converted to Contact and was added opportunity during conversion. field name is Lead_Status__c (picklist field)


User-added image


Thank you for the answer

Israel
Hi All,

I'm quite new into development and I was looking for answer. We need to have a particular picklist field(Lead_Status__c) in Contact be updated to "Qualified" after the lead was converted with an Opportunity (during conversion of the lead, optionally adding new Opportunity). 

We tried to use workflow and process builder but it end up as "false" in the debug log, so the option is via apex. I manage to do some search in sites and found this code:
 
Trigger Lead on Lead (after update) {

    if (Trigger.isAfter) {

        if (Trigger.isUpdate) { 

            Map<ID,ID> oppToContact = new Map<ID,ID>(); 

            for (Lead ld : Trigger.new) {
                if(ld.isConverted && trigger.oldMap.get(ld.id).isConverted) continue; //only process newly converted leads

                // Find all converted Leads with Opportunitiy and add ConvertedOpportunityId to setConvertedOppIds
                if (ld.ConvertedOpportunityId != null && ld.ConvertedContactId != null){                    
                    oppToContact.put(ld.ConvertedOpportunityId,ld.ConvertedContactID);  

                }

            }
I might need to find the additional code to add here to update the Lead Status in Contact if this particular record was converted from a lead and with added opportunity upon conversion, can anyone please help me on this code? Im quite new in this development and would really like to explore further. Please see image below of the supposed field to update when the Lead converted to Contact and was added opportunity during conversion. field name is Lead_Status__c (picklist field)


User-added image


Thank you for the answer

Israel