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

Associating a Custom Object with a Contact on Lead Conversion

I have a custom object that stores Marketing Activity.  It can be associated with either a Lead or a Contact.  When a lead that has associated object is converted I would like to update the custom record to reflect the new ContactId so that the activity will be preserved in the related list. 


Does anybody have any pointers on how to do this?





Hi Phil


One possibilty would be to have after insert trigger on Contact that searches the lead object for a field 'ConvertedContactId' that matches the new contactId. When you've found one that matches it's simply a case of removing the lead id on your custom object and putting in the contact id (I'm assuming they're seperate fields...).






Pretty sure the best way is a lead trigger after update that checks for IsConverted=True and ConvertedContactId.

Felix ZFelix Z

Is there a tutorial on this task?

My organization just start using Salesforce and the first Custom object i configured I already need to do this.

This must be very common type of request. 


Did you ever find a way to do this?  We are needing this as well and I can't figure out how to write my trigger for it.


I found a wonderful resource that was able to help me with this.  Here is the code I'm using:


trigger UpdateOHObject_Trigger on Lead (after update) {

  Map<Id, Lead> leadMap = new Map<Id,Lead>();
  Lead parent;
  for (Integer i = 0; i <; i++){
    if ([i].IsConverted == true && Trigger.old[i].isConverted == false) {
  if( leadMap.size() > 0 ) {
      Set<Id> leadIds = leadMap.keySet();
      List<Opportunity_Headings__c> allChildren =
        [select Id, Opportunity__c, Account__c, Lead__c from Opportunity_Headings__c where lead__c in :leadIds];      
      for ( Opportunity_Headings__c child : allChildren ) {
        if ( leadMap.containsKey( child.Lead__c ) ) {
           // lookup the parent lead
           parent = leadMap.get( child.Lead__c );
           // update the fields on the child object
           child.opportunity__c = parent.ConvertedOpportunityId;
           child.account__c = parent.ConvertedAccountId;


    //try {
      update allChildren;
   // } catch( Exception e ) {
         // could put something here to notify on error
         // otherwise it fails silently
   // }



Thanks again Robert!!