You are here

function sf_notifications_update_record in Salesforce Suite 6.2

Same name and namespace in other branches
  1. 7.2 sf_notifications/sf_notifications.module \sf_notifications_update_record()

Helper function for _sf_notifications_handle_message() - attempt to update (or insert if $object_record['oid'] is empty) the local object data, given the salesforce object_record.

1 call to sf_notifications_update_record()
_sf_notifications_handle_message in sf_notifications/sf_notifications.module
Loop through an array of SObjects from SalesForce and save them according to any existing sf fieldmaps, notification settings, and data.

File

sf_notifications/sf_notifications.module, line 298

Code

function sf_notifications_update_record($object_record) {
  $success = TRUE;
  $drupal_type = $object_record['drupal_type'];
  if (empty($drupal_type)) {
    $map = salesforce_api_fieldmap_load($object_record['name']);
    if (empty($map)) {
      $success = FALSE;
    }
    else {
      $drupal_type = $map->drupal;
    }
  }
  if (strpos($drupal_type, 'node_') === 0) {
    $drupal_type = 'node';
  }
  $function = 'sf_' . $drupal_type . '_import';
  if (function_exists($function)) {
    $drupal_id = $function($object_record['fields'], $object_record['name'], $object_record['oid']);
    if ($drupal_id) {
      salesforce_api_log(SALESFORCE_LOG_ALL, 'SalesForce Notificaitions successful ' . $object_record['operation'] . ' of ' . $drupal_type . ' ' . $drupal_id);
    }
    else {
      salesforce_api_log(SALESFORCE_LOG_ALL, 'SalesForce Notificaitions failed to update ' . $object_record['drupal_type'] . ' from record.
        <pre>' . print_r($object_record, 1) . '</pre>');
      $success = FALSE;
    }
  }
  else {
    salesforce_api_log(SALESFORCE_LOG_ALL, 'SalesForce Notifications: Import handler ' . $function . ' undefined.
        Drupal ' . $object_record['drupal_type'] . ' with id ' . $object_record['oid'] . ' was not updated.');
    $success = FALSE;
  }
  return $success;
}