You are here

function salesforce_api_describeSObjects in Salesforce Suite 7.2

Same name and namespace in other branches
  1. 6.2 salesforce_api/salesforce_api.module \salesforce_api_describeSObjects()
  2. 7 salesforce_api/salesforce_api.module \salesforce_api_describeSObjects()

Wrapper for SOAP SforceBaseClient::describeSObjects Given an array of sf object type, return an associative, normalized array of SF object definitions, indexed on machine-readable names of SObjects

Parameters

array types : an array of machine-readable names to SObjects:

3 calls to salesforce_api_describeSObjects()
salesforce_api_cache_build in salesforce_api/salesforce_api.module
Recreate the Salesforce object cache.
salesforce_api_demo in salesforce_api/salesforce_api.admin.inc
Demonstrates some of the API functionality through the Salesforce class and fieldmap functionality.
salesforce_api_describeSObject in salesforce_api/salesforce_api.module
Wrapper for SOAP SforceBaseClient::describeSObject Given an sf object type, return the SF Object definition

File

salesforce_api/salesforce_api.module, line 1957
Defines an API that enables modules to interact with the Salesforce server.

Code

function salesforce_api_describeSObjects($types) {
  static $objects;
  if (is_string($types)) {
    $types = array(
      $types,
    );
  }
  if (!is_array($types)) {
    if (user_access('administer salesforce')) {
      drupal_set_message(t('DescribeSObjects expects an array. ' . gettype($types) . ' received.'), 'error');
    }
    return FALSE;
  }
  $types = array_filter($types);

  // There is no reason to describe the same object twice in one HTTP request.
  // Use a static cache to save API calls and bandwidth.
  if (!empty($objects)) {
    $outstanding = array_diff($types, array_keys($objects));
    if (empty($outstanding)) {
      $ret = array();
      foreach ($types as $k) {
        $ret[$k] = $objects[$k];
      }
      return $ret;
    }
  }
  if (is_string($types)) {
    $types = array(
      $types,
    );
  }
  try {
    $sf = salesforce_api_connect();
    if ($sf === FALSE) {
      $link = l('Please verify that you have completed your Salesforce credentials', SALESFORCE_PATH_ADMIN);
      if (user_access('administer salesforce')) {
        drupal_set_message(t('Unable to connect to Salesforce. !link', array(
          '!link' => $link,
        )), 'error');
      }
      return;
    }
    $objects = $sf->client
      ->describeSObjects(array_values($types));
  } catch (Exception $e) {
    salesforce_api_log(SALESFORCE_LOG_SOME, 'Unable to establish Salesforce connection while issuing describeSObjects API call.', array(), WATCHDOG_ERROR);
  }
  if (empty($objects)) {
    return array();
  }

  // This is the normalization part: If only one object was described, Salesforce
  // returned an object instead of an array. ALWAYS return an array of objects.
  if (is_object($objects)) {
    $objects = array(
      $objects,
    );
  }

  // And make it an associative array for good measure.
  $tmp = array();
  foreach ($objects as $o) {
    $tmp[$o->name] = $o;
  }
  $objects = $tmp;
  return $objects;
}