You are here

function hook_sf_find_match in Salesforce Suite 6.2

Same name and namespace in other branches
  1. 7 hooks.php \hook_sf_find_match()
  2. 7.2 salesforce_api.api.php \hook_sf_find_match()

Retrieve matching object ids before creating a new object. This hook is designed to eliminate creation of duplicate objects if so desired. For example, an implementation of sf_user_sf_find_match might query Salesforce for Ids matching the user's email address before creating a new Contact.

IMPORTANT: implementations of this function MUST ensure that matches are not IDs of deleted records in Salesforce. By default SOQL query() filters out deleted records, so sf_prematch_sf_find_match() fulfils this requirement.

Parameters

$direction: "import" or "export"

$fieldmap_type: "user", "node", etc.

$object: The data object, probably $user or $node

$fieldmap_id: The id of the fieldmap being used to import or export the current object.

Return value

'import': an array of matching nid's, uid's, etc. 'export': an array of matching Salesforce Id's @see IMPORTANT note above.

1 function implements hook_sf_find_match()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

sf_prematch_sf_find_match in sf_prematch/sf_prematch.module
Implement hook_sf_find_match
1 invocation of hook_sf_find_match()
salesforce_api_search_for_duplicates in salesforce_api/salesforce_api.module

File

./hooks.php, line 149
These are the hooks that are invoked by the Salesforce core.

Code

function hook_sf_find_match($direction, $fieldmap_type, $object, $fieldmap_name) {
  if ($direction == 'export' && ($fieldmap_type == 'user' || $fieldmap_type == 'node' && $object == 'profile')) {
    if (empty($object->mail)) {
      $object->mail = db_result(db_query('SELECT mail FROM {user} WHERE uid = %d', $object->uid));
    }
    $sf = salesforce_api_connect();
    if (!is_object($sf)) {
      watchdog('sf_find_match', 'Salesforce connection failed when looking for a match.');
      return;
    }
    $result = $sf->client
      ->query('SELECT Id FROM Contact WHERE Email = \'' . $obj->mail . '\'');
    if (count($result->records)) {
      return array(
        $result->records[0]->Id,
      );
    }
  }
}