You are here

function hook_salesforce_push_success in Salesforce Suite 7.3

Same name and namespace in other branches
  1. 8.4 salesforce.api.php \hook_salesforce_push_success()
  2. 8.3 salesforce.api.php \hook_salesforce_push_success()
  3. 5.0.x salesforce.api.php \hook_salesforce_push_success()

A salesforce push has succeeded: Implementations may wish to react, for example, by alerting an administrator.

Parameters

string $op: The salesforce operation: Create, Update, Upsert, or Delete

object $result: The salesforce response

array $synced_entity: Entity data for this push. This array has 4 keys 'entity_wrapper': entity_metadata_wrapper() for the Drupal entity 'mapping_object': salesforce mapping object record, if it exists. Otherwise null 'queue_item': If this is a SOAP push, Drupal queue item corresponding to this push attempt. Otherwise FALSE. 'mapping': SalesforceMapping being used for this push

Related topics

2 invocations of hook_salesforce_push_success()
salesforce_push_process_soap_results in modules/salesforce_push/salesforce_push.module
Process SOAP API batch results.
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 229
These are the hooks that are invoked by the Salesforce core.

Code

function hook_salesforce_push_success($op, $result, $synced_entity) {
  $mapping_object = FALSE;
  if (!empty($synced_entity['mapping_object'])) {
    $mapping_object = $synced_entity['mapping_object'];
  }
  if (drupal_strtolower($op) == 'delete' && $mapping_object) {
    $mapping_object
      ->delete();
    return;
  }
  if (!$mapping_object) {

    // Create mapping object, saved below.
    $wrapper = $synced_entities[$key]['entity_wrapper'];
    list($entity_id) = entity_extract_ids($wrapper
      ->type(), $wrapper
      ->value());
    $mapping_object = entity_create('salesforce_mapping_object', array(
      'entity_id' => $entity_id,
      'entity_type' => $wrapper
        ->type(),
      'salesforce_id' => $result->id,
      'last_sync_message' => t('Mapping object created via !function.', array(
        '!function' => __FUNCTION__,
      )),
    ));
  }
  else {
    $mapping_object->last_sync_message = t('Mapping object updated via !function.', array(
      '!function' => __FUNCTION__,
    ));
  }
  $mapping_object->last_sync_status = SALESFORCE_MAPPING_STATUS_SUCCESS;
  $mapping_object->last_sync = REQUEST_TIME;
  $mapping_object->last_sync_action = 'push';
  $mapping_object
    ->save();
  watchdog('salesforce_push', '%op: Salesforce object %id', array(
    '%id' => $result->id,
    '%op' => $op,
  ));
}