I got a question, after a node is linked to a Salesforce lead, and then the Lead is manually converted to a Contact in Salesforce, will this change be sent back to the module and update the mapping table?

If this feature is not supported by this module, is there any way to accomplish this?

Thanks in advance.

Comments

kostajh’s picture

Status: Active » Fixed

There's currently nothing in the Suite to handle this. You will need to write a custom module that implements the pre_import and post_export hook. In your post_export hook you'll want something like this (note I've defined constants for my fieldmap names):

function my_module_salesforce_api_post_export($sf_object, $name, $drupal_id, $response) {
  if ($response) {
    if (is_array($response->errors)) {
      $response->errors = $response->errors[0];
    }
    if ($response->errors->statusCode == 'CANNOT_UPDATE_CONVERTED_LEAD') {
      if ($name == MY_SITE_LEAD_FIELDMAP && $drupal_id) {
        // We need to update the object map to reference this as a Contact
        $new_object = salesforce_api_retrieve(array($sf_object->Id), $name);
        if (is_array($new_object)) {
          $new_object = $new_object[0];
        }
        if ($converted_sfid = $new_object->ConvertedContactId) {
          sf_user_export($drupal_id, MY_SITE_CONTACT_FIELDMAP, $converted_sfid);
        }
      }
    }
  }
}

In pre_import hook you'll want something like this:

  // Handle Leads that are converted to contacts
  if ($sf_data->ConvertedContactId && $name == MY_SITE_LEAD_FIELDMAP) {
    // The person has been converted to a Contact but we are using the Lead
    // fieldmap so we need to use the Contact fieldmap for import
    $name = MY_SITE_CONTACT_FIELDMAP;
    sf_user_import($sf_data->ConvertedContactId, $name, $sf_data->Drupal_ID__c);
    return FALSE;
  }
kurtzhong’s picture

Thank you very much, this helps a lot.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.