Created
November 18, 2010 08:58
-
-
Save ericabouaf/704792 to your computer and use it in GitHub Desktop.
Example on how to use the RForce gem with Salesforce SOQL queries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'rforce' | |
require 'base64' | |
# Install: | |
# sudo gem install rforce | |
# sudo gem install facets -v 2.4 | |
# | |
# Important: rforce 0.4.1 is not compatible with facets 2.9 ! | |
# Login | |
binding = RForce::Binding.new 'https://www.salesforce.com/services/Soap/u/16.0' | |
binding.login 'user@domain.com', 'password_with_token' | |
puts "Login successful !" | |
# Find the record | |
answer = binding.query :queryString => "SELECT Id,Name from Account Where Id='0013000000MlcEoAAJ' Limit 1" | |
puts answer.queryResponse.result.records.inspect | |
# Query custom object | |
answer = binding.query :queryString => "SELECT Id,Name,Date_de_facture__c,Total_TTC__c from Facture__c Where Compte__c='0013000000MlcEoAAJ' AND PDF_genere__c=TRUE Order by CreatedDate" | |
f = answer.queryResponse.result.records | |
puts f.inspect | |
# Get an attachment ant stores it into a file | |
answer = binding.query :queryString => "Select SystemModstamp, ParentId, OwnerId, Name, LastModifiedDate, LastModifiedById, IsPrivate, IsDeleted, Id, CreatedDate, CreatedById, ContentType, BodyLength, Body From Attachment a Where ParentId='"+f[:Id].first+"'" | |
doc = answer.queryResponse.result.records | |
File.open(f[:Name]+'.pdf', 'w') do |io| | |
io << Base64.decode64(doc[:Body]) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment