Drush integration
jmiccolis - April 28, 2009 - 18:45
| Project: | Salesforce |
| Version: | 6.x-2.x-dev |
| Component: | User interface |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Bevan |
| Status: | closed |
| Issue tags: | drush, Needs Documentation |
Description
Attached is a new drush include file that enables you to use the command line to query your salesforce data. It adds three new commands to drush:
- "soql show tables" Basically mimicks mysql's show tables, ie it lists out what object types can run soql queries against.
- "soql describe" Lets you inspect a object (and it's components) in salesfoce
- "soql" Run a soql query from the command line! yay.
Hope it's useful.

#1
File uploading didn't take. take two.
#2
We're using this in production for exploring SF repositories and building queries. This really makes our work faster.
Setting to needs review.
#3
Oh goodie! I wish I'd had this a week ago! :)
#4
I put the file in /salesforce_api/salesforce_api.drush.inc.
I can see all 3 SOQL commands in drush help, but I get the following error when I try to run any soql command
Fatal error: Class 'SoapClient' not found in [snip]/SforceBaseClient.php on line 121. admin/settings/salesforce/demo connects fine.bevan@Bevans-MacBook.local:~/sites/csf/sites/csf
> drush
Execute a drush command. Run `drush help [command]` to view command-specific
help.
Examples:
drush dl cck zen Download CCK module and Zen theme.
[snip]
generate content Creates content.
soql show tables List tables in salesforce.
soql describe Describe an individual table in salesforce.
soql Execute a SOQL query.
bevan@Bevans-MacBook.local:~/sites/csf/sites/csf
> drush soql show tables
Fatal error: Class 'SoapClient' not found in [snip]/SforceBaseClient.php on line 121
bevan@Bevans-MacBook.local:~/sites/csf/sites/csf
> drush soql describe
Fatal error: Class 'SoapClient' not found in [snip]/SforceBaseClient.php on line 121
bevan@Bevans-MacBook.local:~/sites/csf/sites/csf
> drush soql
Fatal error: Class 'SoapClient' not found in [snip]/SforceBaseClient.php on line 121
#5
A buddy of mine ran into this yesterday.
salesforce module works fine through your browser, right?
so, my guess is that your command line php instance is
1) different from your web php instance (for example if you're using X/M/WAMP) and
2) not configured with --enable-soap
try executing drush with the exact same php instance you use for apache.
#6
Good spotting. That was the issue – Thanks! Since Drush is a tool for development environments, I think we need to handle this error a bit better. E.g. "Have you enabled SOAP? If you can connect through the browser, make sure your command line PHP binary is the same as your web server's PHP binary. Use the command which php to help determine what binary is being used on the CLI."
Also, the help documents need fleshing out. The all need at least one example, in the same format as other Drush help docs. The soql command needs a few examples, some which actually work in most SF environments. It also needs links on how to find out more about how to use soql, and what soql is.
Otherwise, this is totally awesome and RTBC.
#7
Great, glad everybody else if finding this useful. I'll post and updated file later this week which checks php compat and has some better docs.
#8
I've added better help, better display on soql describe when fields are requested, and now check for the soap extension.
#9
file upload failed, trying again.
#10
#11
Committed in #208928 to DRUPAL-6--2. Nice work, and nice blog post! :)
#12
Automatically closed -- issue fixed for 2 weeks with no activity.
#13
Have been enjoying this for some time.
Yesterday switched to new All-Versions-2.0 Drush, which is working fine; however, when I use the "drush soql" commands that were working fine previously, now I get invisible output.
The query is made ok, and the data returned from SF, but the data itself is not printed. For example:
$ drush soql show tables
... (142 lines) ...
142 rows in set.
Another example:
$ drush soql select Id from Contact where Email = \'someone@someone.net\'
1 rows in set (2.68 sec)
Programmatically, I am getting data, so I wonder if this is happening to anyone else using "drush soql" commands with the All-Versions-2.0 drush release.
Again, thanks a million for this wonderful drush extension!
#14
yes, the drush table printing api changed recently. This should be a quick fix
#15
This is a separate issue, please create a new ticket/issue-node.