function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
m_roarkm_roark 

Fetching Lead fields to update Contact fields in a trigger fired by 'Convert Lead'?

All,

 

I have had a request from a user, and I am struggling with how to accomodate it. 

 

My user works with Leads, and is frustrated that the address information input for the Leads is not transferred to the new Contact created when the Lead is converted.  I have looked into the standard functionality, and have found that this information is instead transferred to the Account which is created.  I can create a new set of custom fields for both the Lead and Contact records to transfer this information, but I don't feel this adequately meets my users' needs.

 

Instead, I am trying to determine if I can update the Contact information as it is being created by the 'Convert Lead' process, using an APEX trigger.  Unfortunately, I can find little information about how triggers relate to the 'Convert Lead' process.  I have looked at the discussion boards, blogs, and developer's guide, but cannot seem to find the information I need. 

 

I am aware that I may need to request that the 'Enforce Validation and Triggers from Lead Convert' functionality be enabled in my org, and that this will allow me to use the 'before create' trigger setting to create a trigger on the Contact object which will allow me to update the fields in the Contact record before it is saved.  However, how do I access the original Lead in the trigger to allow me to grab the address information stored in the Lead?

 

Any help would be greatly appreciated.

Message Edited by m_roark on 03-10-2009 03:03 PM
Best Answer chosen by Admin (Salesforce Developers) 
WhyserWhyser

hmm.. I didn't know that. Thanks for the info.

 

well if that's the case then I would write a trigger like so

 

trigger UpdateContactAddressUponLeadConversion on Lead( after update ) { // Instantiate a list of Contacts to update List< Contact > cList = new List< Contact >(); for ( Lead l : Trigger.new ) { // Check to see if the lead was converted into a Contact if ( l.ConvertedContactId != null ) { // Get the Contact to update Contact c = [select id, MaillingCity, MailingCountry, MailingPostalCode, MailingState, MailingStreet from Contact where id = :l.ConvertedContactId]; // Update the Address fields c.MaillingCity = l.City; c.MailingCountry = l.Country; c.MailingPostalCode = l.PostalCode; c.MailingState = l.State; c.MailingStreet = l.Street; cList.add( c ); } } // Update the Contacts update cList; }

 

All Answers

WhyserWhyser

Instead of solving this via APEX, why don't you create formula fields that are the same value as the Lead's address fields.

Then map those formula fields to the Contact Address fields upon lead conversion. Then you won't have to deal with all those silly APEX rules.

m_roarkm_roark

Whyser,

 

That is a great question.  The problem is that I cannot map custom Lead fields to standard Contact fields.  The ability to perform this mapping has been requested on the AppExchange, but does not appear to be currently under consideration for inclusion in SalesForce.

 

WhyserWhyser

hmm.. I didn't know that. Thanks for the info.

 

well if that's the case then I would write a trigger like so

 

trigger UpdateContactAddressUponLeadConversion on Lead( after update ) { // Instantiate a list of Contacts to update List< Contact > cList = new List< Contact >(); for ( Lead l : Trigger.new ) { // Check to see if the lead was converted into a Contact if ( l.ConvertedContactId != null ) { // Get the Contact to update Contact c = [select id, MaillingCity, MailingCountry, MailingPostalCode, MailingState, MailingStreet from Contact where id = :l.ConvertedContactId]; // Update the Address fields c.MaillingCity = l.City; c.MailingCountry = l.Country; c.MailingPostalCode = l.PostalCode; c.MailingState = l.State; c.MailingStreet = l.Street; cList.add( c ); } } // Update the Contacts update cList; }

 

This was selected as the best answer
m_roarkm_roark

Whyser,

 

Thank you so much for your time and feedback.  The suggested solution worked beautifully. 

 

I guess I just needed some more information about how Leads stored their connection to the Contacts records converted from them.