function drush_salesforce_sf_describe_object in Salesforce Suite 5.0.x
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()
- 7.3 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 178 - Drush integration for Salesforce.
Code
function drush_salesforce_sf_describe_object($object_name = NULL) {
_drush_salesforce_deprecated();
if (!$object_name) {
return drush_log('Please specify an object as an argument.', 'error');
}
$salesforce = \Drupal::service('salesforce.client');
$object = $salesforce
->objectDescribe($object_name);
// Return if we cannot load any data.
if (!is_object($object)) {
return drush_log(dt('Could not load data for object !object', [
'!object' => $object_name,
]), 'error');
}
$output = drush_get_option('output');
switch ($output) {
case 'raw':
drush_print_r($object->data);
return;
case 'fields':
$rows = [
[
'Name',
'Type',
'Label',
],
];
foreach ($object->fields as $field) {
$rows[] = [
$field['name'],
$field['type'],
$field['label'],
];
}
drush_print_table($rows, TRUE);
return;
case 'field':
$fieldname = drush_get_option('field');
if (empty($fieldname)) {
drush_log(dt('Please specify a field name'), 'error');
return;
}
try {
$field_data = $object
->getField($fieldname);
} catch (\Exception $e) {
watchdog_exception('salesforce.drush', $e);
drush_log(dt('Could not load data for field !field on !object object', [
'!field' => $fieldname,
'!object' => $object_name,
]), 'error');
return;
}
drush_print_r($field_data);
return;
default:
if ($output != 'info') {
drush_log(dt('Unkonwn output option !output', [
'!output' => $output,
]), 'error');
return;
}
// Display information about the object.
$rows = [];
$rows[] = [
'Name',
$object->name,
];
$rows[] = [
'Label',
$object->label,
];
$rows[] = [
'Field count',
count($object
->getFields()),
];
$rows[] = [
'SFID prefix',
$object->keyPrefix,
];
$rows[] = [
'Child Relationships',
isset($object->childRelationships) ? count($object->childRelationships) : 0,
];
$rows[] = [
'Searchable',
$object->searchable == 1 ? 'TRUE' : 'FALSE',
];
$rows[] = [
'Creatable',
$object->createable == 1 ? 'TRUE' : 'FALSE',
];
$rows[] = [
'Deletable',
$object->deletable == 1 ? 'TRUE' : 'FALSE',
];
$rows[] = [
'Mergeable',
$object->mergeable == 1 ? 'TRUE' : 'FALSE',
];
$rows[] = [
'Queryable',
$object->queryable == 1 ? 'TRUE' : 'FALSE',
];
drush_print_table($rows);
return;
}
}