You need to sign in to do that
Don't have an account?

Ruby Utility scripts
I am trying to build some Ruby utility scripts. Eventual I would like to replicate some basic export and import data scripts like Data Loader as a command line utility. Please stop me now if I am barking up the wrong tree. I am able to generate scaffolding through rails no problem using the scaffold generator(I have heard reference to a asfscaffold but can't find it.) But I would like to dump sObject data to a csv file.
the follow script works and generates a list of objects:
but I can't seem to figure out the syntax to describeSObjects syntax I have:
mySobjects = ['Contact', 'Account']
list = ActiveRecord::Base.connection.binding.describeSObjects(mySobjects).results
which returns nil
Can someone help me with this syntax?
Also an example of a query would be great too.
Thanks
Kyle
the follow script works and generates a list of objects:
require 'rubygems'
require 'activesalesforce'
ActiveRecord::Base.establish_connection(
:adapter => 'activesalesforce',
:username => '',
:password => '',
:url => 'https://www.salesforce.com' )
sObjects = ActiveRecord::Base.connection.binding.describeGlobal([]).describeGlobalResponse.result.types.sort
puts sObjects
but I can't seem to figure out the syntax to describeSObjects syntax I have:
mySobjects = ['Contact', 'Account']
list = ActiveRecord::Base.connection.binding.describeSObjects(mySobjects).results
which returns nil
Can someone help me with this syntax?
Also an example of a query would be great too.
Thanks
Kyle
This works.
binding.describeSObjects([:sObjectType,'Contact',:sObjectType,'Account'])
For every call, you have to pass a hash or array (with alternating keys/values as above) where the key is the parameter *name* expected in the WSDL. There appears to be no way to pass the above as a hash (as the request takes multiple 'sObjectType' elements, and passing :sObjectType => ['Contact','Account'] doesn't work).
Vijay
I am just getting a nil returned:
Here is my script
require 'rubygems'
require 'activesalesforce'
ActiveRecord::Base.establish_connection(
:adapter => 'activesalesforce',
:username => removed
:password => removed,
:url => 'https://www.salesforce.com' )
sObjects = ActiveRecord::Base.connection.binding.describeSObject([:sObjectType,'Contact',:sObjectType,'Account'])
puts sObjects.SoapResponse
Am I missing something obvious.
Also I noticed that if I generate a scaffold I can run
>> q = Account.find(:all)
from the console and get a result set. But I can't script this for the life of me.
Any ideas?
Kyle
1. you should be using describeSObjects and not describeSObject (which works for one object, of course ;-))
2. if you use
#!/usr/bin/env script/runner
as the first line of your script
you can simply do
Account.find(:all)
in your script.
(of course you still need to generate the Account model object (which your scaffold generation does for you)).
require 'rubygems'
require 'yaml'
require 'activesalesforce'
ActiveRecord::Base.establish_connection(
:adapter => 'activesalesforce',
:username => '',
:password => '',
:url => 'https://www.salesforce.com' )
@sf_connection = ActiveRecord::Base.connection
# The following describes all globals in Salesforce account. Noice!
# result = @sf_connection.binding.describeGlobal([]).describeGlobalResponse.result
# puts result.types.sort
# The following prints sort-of nice results for the structure of the fields
list = @sf_connection.binding.describeSObjects(:sObjectType => "SINGLE_OBJECT_NAME").describeSObjectsResponse.result.fields
puts list.to_yaml
I assume (but haven't tried...) that the single hash could be replaced with an array as in the previous examples