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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jmiccolis’s picture

File uploading didn't take. take two.

alex_b’s picture

Status: Active » Needs review

We're using this in production for exploring SF repositories and building queries. This really makes our work faster.

Setting to needs review.

Bevan’s picture

Oh goodie! I wish I'd had this a week ago! :)

Bevan’s picture

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
AaronBauman’s picture

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.

Bevan’s picture

Status: Needs review » Needs work
Issue tags: +Needs documentation, +drush

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.

jmiccolis’s picture

Assigned: Unassigned » jmiccolis

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.

jmiccolis’s picture

Assigned: jmiccolis » Unassigned
Status: Needs work » Needs review

I've added better help, better display on soql describe when fields are requested, and now check for the soap extension.

jmiccolis’s picture

file upload failed, trying again.

Bevan’s picture

Assigned: Unassigned » Bevan
Bevan’s picture

Status: Needs review » Fixed

Committed in #208928 to DRUPAL-6--2. Nice work, and nice blog post! :)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

victorkane’s picture

Status: Closed (fixed) » Active

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!

jmiccolis’s picture

yes, the drush table printing api changed recently. This should be a quick fix

Bevan’s picture

Status: Active » Closed (fixed)

This is a separate issue, please create a new ticket/issue-node.