function hook_salesforce_push_mapping_object_alter in Salesforce Suite 7.3
Same name and namespace in other branches
- 8.4 salesforce.api.php \hook_salesforce_push_mapping_object_alter()
- 8.3 salesforce.api.php \hook_salesforce_push_mapping_object_alter()
- 5.0.x salesforce.api.php \hook_salesforce_push_mapping_object_alter()
Define or alter the mapping object during a push.
Parameters
mixed $mapping_object: The mapping object that was detected based on existing mappings or FALSE if no exisitng mapping object exists.
object $entity: The Drupal entity that is being pushed.
SalesforceMapping $mapping: The salesforce mapping that will be used during the push.
Related topics
2 invocations of hook_salesforce_push_mapping_object_alter()
- salesforce_push_cron in modules/
salesforce_push/ salesforce_push.module - Implements hook_cron().
- salesforce_push_sync_rest in modules/
salesforce_push/ salesforce_push.module - Sync Drupal entities and Salesforce objects using the REST API.
File
- ./
salesforce.api.php, line 78 - These are the hooks that are invoked by the Salesforce core.
Code
function hook_salesforce_push_mapping_object_alter(&$mapping_object, $entity, $mapping) {
// Do some prematching for outgoing user pushes if we don't already have a
// match.
if (!$mapping_object && $mapping->drupal_entity_type == 'user') {
// Run some complex custom prematching logic that queries Salesforce for an
// existing contact (beyond a basic external key comparison) that is a match
// to this Drupal user.
$matched_contact = mymodule_custom_sf_push_prematch($entity, $mapping);
if ($matched_contact) {
// If we have a match create mapping object on-the-fly and then reload it
// This means that the rest of the push logic will target this matched
// contact instead of creating a new one.
entity_create('salesforce_mapping_object', array(
'salesforce_id' => $matched_contact['Id'],
'entity_type' => $mapping->drupal_entity_type,
'entity_id' => $entity->uid,
'last_sync_message' => t('User prematch on push'),
'last_sync_status' => SALESFORCE_MAPPING_STATUS_SUCCESS,
))
->save();
$mapping_object = salesforce_mapping_object_load_by_drupal('user', $entity->uid, TRUE);
}
}
}