function drush_salesforce_sf_describe_object in Salesforce Suite 7.3
Same name and namespace in other branches
- 8.4 salesforce.drush.inc \drush_salesforce_sf_describe_object()
- 8.3 salesforce.drush.inc \drush_salesforce_sf_describe_object()
- 5.0.x salesforce.drush.inc \drush_salesforce_sf_describe_object()
Describes a Salesforce object.
Use the --fields option to display information about the fields of an object, or the --field-data option to display information about a single field in an object.
Parameters
string $object_name: The name of a Salesforce object to query.
File
- ./
salesforce.drush.inc, line 126 - Drush integration for Salesforce.
Code
function drush_salesforce_sf_describe_object($object_name = NULL) {
if (!$object_name) {
return drush_log('Please specify an object as an argument.', 'error');
}
$salesforce = _drush_salesforce_drush_get_api();
$object = $salesforce
->objectDescribe($object_name);
// Return if we cannot load any data.
if (!is_array($object)) {
return drush_log(dt('Could not load data for object !object', array(
'!object' => $object,
)), 'error');
}
// Display only information about fields for an option,
if (drush_get_option('fields')) {
$rows = array(
array(
'Name',
'Type',
'Label',
),
);
foreach ($object['fields'] as $field) {
$rows[] = array(
$field['name'],
$field['type'],
$field['label'],
);
}
drush_print_r($rows);
drush_print_table($rows, TRUE);
return;
}
// Display only information about a specific field.
if ($fieldname = drush_get_option('field-data')) {
$field_data = NULL;
foreach ($object['fields'] as $field) {
if ($field['name'] === $fieldname) {
$field_data = $field;
break;
}
}
if (!$field_data) {
drush_log(dt('Could not load data for field !field on !object object', array(
'!field' => $fieldname,
'!object' => $object_name,
)), 'error');
}
else {
drush_print_r($field);
}
return;
}
// Display information about the object.
// @TODO add remaining field objects?
$rows = array();
$rows[] = array(
'Name',
$object['name'],
);
$rows[] = array(
'Fields',
isset($object['fields']) ? count($object['fields']) : 0,
);
$rows[] = array(
'Child Relationships',
isset($object['childRelationships']) ? count($object['childRelationships']) : 0,
);
$rows[] = array(
'Searchable',
$object['searchable'] == 1 ? 'TRUE' : 'FALSE',
);
$rows[] = array(
'Creatable',
$object['createable'] == 1 ? 'TRUE' : 'FALSE',
);
$rows[] = array(
'Deletable',
$object['deletable'] == 1 ? 'TRUE' : 'FALSE',
);
$rows[] = array(
'Mergeable',
$object['mergeable'] == 1 ? 'TRUE' : 'FALSE',
);
$rows[] = array(
'Queryable',
$object['queryable'] == 1 ? 'TRUE' : 'FALSE',
);
drush_print_table($rows);
}