• clshah2
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 0
    Replies

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   

  • September 16, 2011
  • Like
  • 0

Hi,

I have a custom Web Browsing object which is attached to a lead and tracks the lead's browsing history and stores it. When I convert the lead into a contact, the custom object's data (browsing history) does not get added after the conversion and is lost. Is there a way in salesforce to do this or it has to be done via backend code. Any help would be appreciated. 

 

Thank you.