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
clshah2clshah2 

Attaching tasks to custom object on lead conversion

Hi everyone,

I have this trigger for lead conversion which works as intended. Thanks to someone who posted this code before. :)

The problem I am facing is that when the lead is converted to a contact, the custom object and its data gets imported as intended but it doesn't display as it should. Only the Id's of the tasks are displayed. I need the Type and Details fields as well. I have shown below as to how I want it to be . Any help would be appreciated. I just need to know how can I display those fields of the tasks as in the layout provided "Before conversion" below.

 

 Thanks a lot!

 

trigger ConvertLead on Lead (after update) 
{
    Map<Id, Lead> leadMap = new Map<Id, Lead>();
    Lead Parent;
    
    for (Integer i = 0; i < Trigger.new.size(); i++){
    if (Trigger.new[i].IsConverted == true && Trigger.old[i].isConverted == false) {
      leadMap.put( Trigger.new[i].Id, Trigger.new[i]);
    }
  }
   
  if( leadMap.size() > 0 ) {
      Set<Id> leadIds = leadMap.keySet();
      List<Web_Browsing__c> allChildren =
        [select Id, Browsing_History_255__c, Contact__c, Web_Browsing_History__c, Lead__c, Type__c, Browsing_History__c from Web_Browsing__c where lead__c in :leadIds];      
 
 System.debug(allChildren);
   
      for ( Web_Browsing__c child : allChildren ) {
        if ( leadMap.containsKey( child.Lead__c ) ) {
           // lookup the parent lead
           parent = leadMap.get( child.Lead__c );
           //parent = leadType.get ( child.Browsing_History_255__c );
           // update the fields on the child object
           child.contact__c = parent.ConvertedContactId;
           //child.account__c = parent.ConvertedAccountId;
        }
      }

System.debug(allChildren);

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

Before Conversion to Contact

Web Browsing Custom Object Field
       
Action    ID                               Type                     Details            Created Date
             a08Q00000032FSV    File Download      Link                7/21/2011
             a08Q00000032FS6    File Download      Link                 7/21/2011
             a08Q00000032FRr     File Download      Link                7/21/2011
             a08Q00000032FRm   Browsing              Link                7/21/2011

 

After Conversion to Contact

Web Browsing Custom Object Field

 

Action    ID                               Does not display    Does not display  Does not display                
             a08Q00000032FSV        Task name?         Task link?              Created Date?
             a08Q00000032FS6   
             a08Q00000032FRr    
             a08Q00000032FRm