You are here

function hook_sf_find_match in Salesforce Suite 7

Same name and namespace in other branches
  1. 6.2 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.

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

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 97
These are the hooks that are invoked by the Salesforce core.

Code

function hook_sf_find_match($direction, $fieldmap_type, $object, $fieldmap_id) {
  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,
      );
    }
  }
}