function hook_sf_find_match in Salesforce Suite 7.2
Same name and namespace in other branches
- 6.2 hooks.php \hook_sf_find_match()
- 7 hooks.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.
In the core Suite, this hook is implemented by the optional sf_match module.
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"
$entity_name: "user", "node", etc.
$bundle_name: the name of the bundle to which the entity belongs. This is a node type in the case of node entities, or a vocabulary name, or 'user' for users.
$entity: The Drupal entity to be matched, 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 - Implements hook_sf_find_match().
1 invocation of hook_sf_find_match()
- salesforce_api_search_for_duplicates in salesforce_api/
salesforce_api.module - Wrapper function for the sf_find_match hook, implemented by sf_match in the core Salesforce Suite.
File
- ./
salesforce_api.api.php, line 133 - These are the hooks that are invoked by the Salesforce core.
Code
function hook_sf_find_match($direction, $entity_name, $bundle_name, $entity, $fieldmap_name) {
if ($direction == 'export' && ($fieldmap_type == 'user' || $fieldmap_type == 'node' && $bundle_name == 'profile')) {
if (empty($entity->mail)) {
$entity->mail = db_result(db_query('SELECT mail FROM {user} WHERE uid = %d', $entity->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,
);
}
}
}