Leads to Leads Relationship on Conversion

Whoo Hoo! Got it working duh, the relationship on the “Contacts” side should be contacts_contacts_1 not leads_contacts_1

If anyone else needs… here’s the working code:
Here’s the working code: on the lead side the relationship is leads_contacts_1
on the contact side the relationship is contacts_contacts_1

 class DataTransfer
 {
  function doDataTransfer($bean, $events, $arguments)
  {
   $action  = $_REQUEST['action'];
   
   if ($action == 'ConvertLead') //Must confirm it only triggers on conversion!!
   {
    $lead_id  = $bean->id;
    $contact_id = $bean->contact_id;
     
    $bean->load_relationship('leads_contacts_1');
   
    //Remove relationship 
    $rcontacts = array();
    foreach ($bean->leads_contacts_1->getBeans() as $rcontact)
    {
     $rcontact_id = $rcontact->id;
     $rcontacts[] = $rcontact_id;   
    
     $bean->leads_contacts_1->delete($lead_id, $rcontact_id);
    }
   
    
    //Transfer relationship to Contact record
    $contact = new Contact();
    $contact->retrieve($contact_id);
    
    $contact->load_relationship('contacts_contacts_1');
    foreach ($rcontacts as $rcontact)
    {
     $contact->contacts_contacts_1->add($rcontact);
    }
   }
  }
 }

This is setup as a logic hook in custom/modules/Leads/{name of logic hook}. php

1 Like