function drush_salesforce_sf_query_object in Salesforce Suite 7.3
Same name and namespace in other branches
- 8.4 salesforce.drush.inc \drush_salesforce_sf_query_object()
- 8.3 salesforce.drush.inc \drush_salesforce_sf_query_object()
- 5.0.x salesforce.drush.inc \drush_salesforce_sf_query_object()
Query Salesforce objects available to the logged-in user.
Parameters
$name: The object type name, e.g. Account
File
- ./
salesforce.drush.inc, line 316 - Drush integration for Salesforce.
Code
function drush_salesforce_sf_query_object($name) {
$salesforce = _drush_salesforce_drush_get_api();
$fields = drush_get_option('fields', '');
if (!$fields) {
try {
$object = $salesforce
->objectDescribe($name);
} catch (SalesforceException $e) {
drush_log($e
->getMessage(), 'error');
return;
}
$names = array();
foreach ($object['fields'] as $field) {
$names[] = $field['name'];
}
$fields = implode(',', $names);
}
try {
$where = drush_get_option('where', '');
if ($where) {
$where = ' WHERE ' . $where;
}
$query = 'SELECT ' . $fields . ' FROM ' . $name;
// @todo - figure how to leverage SalesforceSelectQuery.
$result = $salesforce
->apiCall('query?q=' . urlencode($query . $where));
drush_print(drush_format($result));
} catch (SalesforceException $e) {
drush_log($e
->getMessage(), 'error');
}
}