I'm trying to perform a bulk query to salesforce with the salesforce_bulk_api gem. I am connecting successfully and doing the query with no problems but I can't get the actual results.

This is what I do:

$- res = salesforce.query("Account", "select id, name from Account limit 3")
$- puts res

It prints:

<?xml version="1.0" encoding="UTF-8"?><jobInfo
 => {"xmlns"=>"http://www.force.com/2009/06/asyncapi/dataload", "id"=>["XXXXXXXXXXXX"], "jobId"=>["XXXXXXXXXXXXXXX"], "state"=>["Completed"], "createdDate"=>["2013-07-01T16:30:37.000Z"], "systemModstamp"=>["2013-07-01T16:30:37.000Z"], "numberRecordsProcessed"=>["3"], "numberRecordsFailed"=>["0"], "totalProcessingTime"=>["0"], "apiActiveProcessingTime"=>["0"], "apexProcessingTime"=>["0"]} 

It says the job is completed but I can't figure out how to extract the results.

May I add that I already followed the procedure explained in the documentation of the gem.


  • The Bulk API Developer's Guide might be helpful. In particular, Chapter 9 on Bulk Query and Chapter 2 Steps 5 (Checking Batch Status) and 6 (Retrieving Batch Result). I'm not familiar with Ruby or the Gem you have linked to understand how the Batch API results should be retrieved. Commented Jul 2, 2013 at 2:50
  • I did the research but I wanted to avoid building a client myself if something already exists. Finally I solved it and added the answer. Thanks!
    – arturodz
    Commented Jul 3, 2013 at 0:13

2 Answers 2


I finally found the answer, it looks like the salesforce_bulk_api gem is not very well documented, fortunately the salesforcebulk gem is. The way to solve this is to:

  1. Authenticate
    client = SalesforceBulk::Client.new(username: 'MyUsername', password: 'MyPasswordWithSecurtyToken')

  1. Add the job
    job = client.add_job(:query, :Account)
  1. Add the batch to the job
    batch = client.add_batch(job.id, "SELECT Id, Name FROM Account")
  1. Close the job
    job = client.close_job(job.id)
  1. Check the job status
    batch = client.batch_info(job.id, batch.id)
  1. Get results from the batch
    results = client.batch_result(jobId, batchId)
  1. Query over the results
    results.each do |result|
      puts result[:Name]

To make things easier I've created salesforce_bulk_query gem: https://github.com/cvengros/salesforce_bulk_query

With this gem you can make a query with a single method call:

result = bulk_api.query("Task", "SELECT Id, Name FROM Task")

All the jobs, batches, etc. are created automatically for you.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .