function salesforce_api_describeSObjects in Salesforce Suite 7
Same name and namespace in other branches
- 6.2 salesforce_api/salesforce_api.module \salesforce_api_describeSObjects()
- 7.2 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 937 - 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)) {
drupal_set_message(t('DescribeSObjects expects an array. @types recieved.', array(
'@types' => gettype($types),
)), 'error');
return FALSE;
}
// 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);
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) {
DrupalSalesforce::watchdog(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;
}