• ybakos
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 7
    Replies

I wanted to post my solution to setting up a Rails 2 application on Heroku with the rforcedotcom/asf-soap-adapter gems.

 

Assumptions:

  1. you want to use both an app database _and_ integrate with Salesforce
  2. you can't put a "salesforce-default-realm" in your database.yml since Heroku generates database.yml for you
  3. you can't use Heroku's DATABASE_URL since this results in violating #1
  4. you don't want your sf_username and sf_password in your repository

I felt this left me with two options:

  1. Create an alternative yml file that contains an entry for RACK_ENV (eg, production) and salesforce-default-realm.
  2. Use an initializer to somehow add the "salesforce-default-realm" to Rails' database configuration.

I personally chose not to go with option #1, since in the Heroku env, if database.yml is generated and "hands-off," I didn't want to hard-code it in the application. But if you want to do this, you should look for config.database_configuration_file.

 

If you choose option #2, then all you need is an initializer that sets ActiveRecord::Base.configurations["salesforce-default-realm"] to the appropriate hash of values.

 

However, things were not as simple as they seemed. My biggest mistake was having the following in my environment.rb:

 

config.gem "asf-soap-adapter", :lib => "asf-soap-adapter"

 

This **bleep**s everything up, because upon app startup, this will cause establish_connection() to be called before your initializer has run. It's absolutely critical that your environment.rb contains:

 

config.gem "asf-soap-adapter", :lib => "activerecord-activesalesforce-adapter"

 

This would have saved me about five hours of poring over the asf source, the activerecord source, and the rails source. But to be honest, it was time well spent: I'm much more familiar with the rails initialization process now. I always wondered why Quinton always wrote "activerecord-activesalesforce-adapter" all the time. Now I know, vaguely.

 

The second issue I had was setting the AR configurations has using the symbol :'salesforce-default-realm' instead of using a string. Use a string, or you'll be as **bleep**ed as I was for a bit.

 

So, here's the skinny. First, create a bare Rails 2.3.x app. Next, create a proper gemset (you are using rvm aren't you?)

 

Gemset
actionmailer (2.3.11)
actionpack (2.3.11)
activerecord (2.3.11)
activeresource (2.3.11)
activesupport (2.3.11)
asf-soap-adapter (1.3.0)
builder (3.0.0)
bundler (1.0.10)
columnize (0.3.2)
configuration (1.2.0)
facets (2.8.4)
faker (0.9.5)
heroku (1.17.15)
heroku_san (1.0.8)
hpricot (0.8.3)
i18n (0.5.0)
json (1.4.6)
launchy (0.3.7)
linecache (0.43)
mime-types (1.16)
mysql (2.8.1)
rack (1.1.0)
rails (2.3.11)
rake (0.8.7)
rcov (0.9.9)
rest-client (1.6.1)
rforcedotcom (20.0.0)
ruby-debug (0.10.4)
ruby-debug-base (0.10.4)

environment.rb:

config.gem "asf-soap-adapter", :lib => "activerecord-activesalesforce-adapter"

 

database.yml:

not in your repo, and specific to your dev and test envs

 

config/initializers/salesforce.rb:

sf_config = {
  :adapter => 'activesalesforce',
  :url => 'https://www.salesforce.com',
  :username => ENV['SF_USERNAME'],
  :password => ENV['SF_PASSWORD'],
  :api_version => '20.0'
}
ActiveRecord::Base.configurations["salesforce-default-realm"] = sf_config

#notice a string is the key to the hash, not a symbol.

 

Lastly, make sure SF_USERNAME and SF_PASSWORD are defined in both your development environment and your Apache Passenger vhost configuration (use SetEnv in your apache config). And of course, make sure those same environment variables are set in your Heroku env.

 

That's all there is to it. I think.

 

 

  • February 25, 2011
  • Like
  • 0

First, thanks for any help from the community and to Quinton for his development efforts, I am grateful.

 

I'm writing to express my frustration at what seems to me to be prolific yet out of date and conflicting documentation regarding SalesForce and Rails integration.

 

Is the "force.com toolkit for ruby" the rforcedotcom gem?

 

As of today, should developers be using activesalesforce, activerecord-salesforce-adapter, or asf-soap-adapter?

 

I haven't been able to accomplish my simple goal: creating a Rails 3.0.4 application that allows me to execute, from the console, Salesforce::SfBase.query_by_sql("select name from Account")

 

rails new someapp

cd someapp

bundle install

script/console

(explosion)

 

Given that my Gemfile states:

 

source 'http://rubygems.org'

gem 'rails', '3.0.4'
gem 'sqlite3'
gem 'asf-soap-adapter'

 

 

And my database.yml states:

 

development:
  adapter: sqlite3
  database: db/development.sqlite3
  pool: 5
  timeout: 5000

salesforce-default-realm:
  adapter: activesalesforce
  url: https://www.salesforce.com
  username: xxx
  password: xxx
  api_version: 20.0

 And my current gemset includes only the following:

 

abstract (1.0.0)
actionmailer (3.0.4)
actionpack (3.0.4)
activemodel (3.0.4)
activerecord (3.0.4)
activerecord-activesalesforce-adapter (2.0.0)
activeresource (3.0.4)
activesalesforce (1.1.6)
activesupport (3.0.4)
arel (2.0.8)
asf-soap-adapter (1.3.0)
builder (2.1.2)
bundler (1.0.10)
erubis (2.6.6)
facets (2.8.4)
hpricot (0.8.3)
i18n (0.5.0)
mail (2.2.15)
mime-types (1.16)
polyglot (0.3.1)
rack (1.2.1)
rack-mount (0.6.13)
rack-test (0.5.7)
rails (3.0.4)
railties (3.0.4)
rake (0.8.7)
rforcedotcom (20.0.0)
sqlite3 (1.3.3)
thor (0.14.6)
treetop (1.4.9)
tzinfo (0.3.24)

 

 

This should freakin' work. But it doesn't. Upon executing rails console:

 

/Users/ybakos/.rvm/gems/ruby-1.8.7-p330@test/gems/activerecord-3.0.4/lib/active_record/connection_adapters/abstract/connection_specification.rb:62:in `establish_connection': salesforce-default-realm database is not configured (ActiveRecord::AdapterNotSpecified)
	from /Users/ybakos/.rvm/gems/ruby-1.8.7-p330@test/gems/asf-soap-adapter-1.3.0/lib/salesforce/sf_base.rb:61
	from /Users/ybakos/.rvm/gems/ruby-1.8.7-p330@test/gems/asf-soap-adapter-1.3.0/lib/asf-soap-adapter.rb:4:in `require'
	from /Users/ybakos/.rvm/gems/ruby-1.8.7-p330@test/gems/asf-soap-adapter-1.3.0/lib/asf-soap-adapter.rb:4
	from /Users/ybakos/.rvm/gems/ruby-1.8.7-p330@test/gems/bundler-1.0.10/lib/bundler/runtime.rb:68:in `require'
	from /Users/ybakos/.rvm/gems/ruby-1.8.7-p330@test/gems/bundler-1.0.10/lib/bundler/runtime.rb:68:in `require'
	from /Users/ybakos/.rvm/gems/ruby-1.8.7-p330@test/gems/bundler-1.0.10/lib/bundler/runtime.rb:66:in `each'
	from /Users/ybakos/.rvm/gems/ruby-1.8.7-p330@test/gems/bundler-1.0.10/lib/bundler/runtime.rb:66:in `require'
	from /Users/ybakos/.rvm/gems/ruby-1.8.7-p330@test/gems/bundler-1.0.10/lib/bundler/runtime.rb:55:in `each'
	from /Users/ybakos/.rvm/gems/ruby-1.8.7-p330@test/gems/bundler-1.0.10/lib/bundler/runtime.rb:55:in `require'
	from /Users/ybakos/.rvm/gems/ruby-1.8.7-p330@test/gems/bundler-1.0.10/lib/bundler.rb:120:in `require'
	from /Users/ybakos/tmp/sftest02/config/application.rb:7
	from /Users/ybakos/.rvm/gems/ruby-1.8.7-p330@test/gems/railties-3.0.4/lib/rails/commands.rb:21:in `require'
	from /Users/ybakos/.rvm/gems/ruby-1.8.7-p330@test/gems/railties-3.0.4/lib/rails/commands.rb:21
	from script/rails:6:in `require'
	from script/rails:6

 

If anyone has successfully created a skeletal Rails 3.x app and has been able to fire up the console and execute Salesforce::SfBase.query_by_sql("select name from Account")

 


Then please do share what steps you took, and what your Gemfile and database.yml state.

 

  • February 15, 2011
  • Like
  • 0

I wanted to post my solution to setting up a Rails 2 application on Heroku with the rforcedotcom/asf-soap-adapter gems.

 

Assumptions:

  1. you want to use both an app database _and_ integrate with Salesforce
  2. you can't put a "salesforce-default-realm" in your database.yml since Heroku generates database.yml for you
  3. you can't use Heroku's DATABASE_URL since this results in violating #1
  4. you don't want your sf_username and sf_password in your repository

I felt this left me with two options:

  1. Create an alternative yml file that contains an entry for RACK_ENV (eg, production) and salesforce-default-realm.
  2. Use an initializer to somehow add the "salesforce-default-realm" to Rails' database configuration.

I personally chose not to go with option #1, since in the Heroku env, if database.yml is generated and "hands-off," I didn't want to hard-code it in the application. But if you want to do this, you should look for config.database_configuration_file.

 

If you choose option #2, then all you need is an initializer that sets ActiveRecord::Base.configurations["salesforce-default-realm"] to the appropriate hash of values.

 

However, things were not as simple as they seemed. My biggest mistake was having the following in my environment.rb:

 

config.gem "asf-soap-adapter", :lib => "asf-soap-adapter"

 

This **bleep**s everything up, because upon app startup, this will cause establish_connection() to be called before your initializer has run. It's absolutely critical that your environment.rb contains:

 

config.gem "asf-soap-adapter", :lib => "activerecord-activesalesforce-adapter"

 

This would have saved me about five hours of poring over the asf source, the activerecord source, and the rails source. But to be honest, it was time well spent: I'm much more familiar with the rails initialization process now. I always wondered why Quinton always wrote "activerecord-activesalesforce-adapter" all the time. Now I know, vaguely.

 

The second issue I had was setting the AR configurations has using the symbol :'salesforce-default-realm' instead of using a string. Use a string, or you'll be as **bleep**ed as I was for a bit.

 

So, here's the skinny. First, create a bare Rails 2.3.x app. Next, create a proper gemset (you are using rvm aren't you?)

 

Gemset
actionmailer (2.3.11)
actionpack (2.3.11)
activerecord (2.3.11)
activeresource (2.3.11)
activesupport (2.3.11)
asf-soap-adapter (1.3.0)
builder (3.0.0)
bundler (1.0.10)
columnize (0.3.2)
configuration (1.2.0)
facets (2.8.4)
faker (0.9.5)
heroku (1.17.15)
heroku_san (1.0.8)
hpricot (0.8.3)
i18n (0.5.0)
json (1.4.6)
launchy (0.3.7)
linecache (0.43)
mime-types (1.16)
mysql (2.8.1)
rack (1.1.0)
rails (2.3.11)
rake (0.8.7)
rcov (0.9.9)
rest-client (1.6.1)
rforcedotcom (20.0.0)
ruby-debug (0.10.4)
ruby-debug-base (0.10.4)

environment.rb:

config.gem "asf-soap-adapter", :lib => "activerecord-activesalesforce-adapter"

 

database.yml:

not in your repo, and specific to your dev and test envs

 

config/initializers/salesforce.rb:

sf_config = {
  :adapter => 'activesalesforce',
  :url => 'https://www.salesforce.com',
  :username => ENV['SF_USERNAME'],
  :password => ENV['SF_PASSWORD'],
  :api_version => '20.0'
}
ActiveRecord::Base.configurations["salesforce-default-realm"] = sf_config

#notice a string is the key to the hash, not a symbol.

 

Lastly, make sure SF_USERNAME and SF_PASSWORD are defined in both your development environment and your Apache Passenger vhost configuration (use SetEnv in your apache config). And of course, make sure those same environment variables are set in your Heroku env.

 

That's all there is to it. I think.

 

 

  • February 25, 2011
  • Like
  • 0

First, thanks for any help from the community and to Quinton for his development efforts, I am grateful.

 

I'm writing to express my frustration at what seems to me to be prolific yet out of date and conflicting documentation regarding SalesForce and Rails integration.

 

Is the "force.com toolkit for ruby" the rforcedotcom gem?

 

As of today, should developers be using activesalesforce, activerecord-salesforce-adapter, or asf-soap-adapter?

 

I haven't been able to accomplish my simple goal: creating a Rails 3.0.4 application that allows me to execute, from the console, Salesforce::SfBase.query_by_sql("select name from Account")

 

rails new someapp

cd someapp

bundle install

script/console

(explosion)

 

Given that my Gemfile states:

 

source 'http://rubygems.org'

gem 'rails', '3.0.4'
gem 'sqlite3'
gem 'asf-soap-adapter'

 

 

And my database.yml states:

 

development:
  adapter: sqlite3
  database: db/development.sqlite3
  pool: 5
  timeout: 5000

salesforce-default-realm:
  adapter: activesalesforce
  url: https://www.salesforce.com
  username: xxx
  password: xxx
  api_version: 20.0

 And my current gemset includes only the following:

 

abstract (1.0.0)
actionmailer (3.0.4)
actionpack (3.0.4)
activemodel (3.0.4)
activerecord (3.0.4)
activerecord-activesalesforce-adapter (2.0.0)
activeresource (3.0.4)
activesalesforce (1.1.6)
activesupport (3.0.4)
arel (2.0.8)
asf-soap-adapter (1.3.0)
builder (2.1.2)
bundler (1.0.10)
erubis (2.6.6)
facets (2.8.4)
hpricot (0.8.3)
i18n (0.5.0)
mail (2.2.15)
mime-types (1.16)
polyglot (0.3.1)
rack (1.2.1)
rack-mount (0.6.13)
rack-test (0.5.7)
rails (3.0.4)
railties (3.0.4)
rake (0.8.7)
rforcedotcom (20.0.0)
sqlite3 (1.3.3)
thor (0.14.6)
treetop (1.4.9)
tzinfo (0.3.24)

 

 

This should freakin' work. But it doesn't. Upon executing rails console:

 

/Users/ybakos/.rvm/gems/ruby-1.8.7-p330@test/gems/activerecord-3.0.4/lib/active_record/connection_adapters/abstract/connection_specification.rb:62:in `establish_connection': salesforce-default-realm database is not configured (ActiveRecord::AdapterNotSpecified)
	from /Users/ybakos/.rvm/gems/ruby-1.8.7-p330@test/gems/asf-soap-adapter-1.3.0/lib/salesforce/sf_base.rb:61
	from /Users/ybakos/.rvm/gems/ruby-1.8.7-p330@test/gems/asf-soap-adapter-1.3.0/lib/asf-soap-adapter.rb:4:in `require'
	from /Users/ybakos/.rvm/gems/ruby-1.8.7-p330@test/gems/asf-soap-adapter-1.3.0/lib/asf-soap-adapter.rb:4
	from /Users/ybakos/.rvm/gems/ruby-1.8.7-p330@test/gems/bundler-1.0.10/lib/bundler/runtime.rb:68:in `require'
	from /Users/ybakos/.rvm/gems/ruby-1.8.7-p330@test/gems/bundler-1.0.10/lib/bundler/runtime.rb:68:in `require'
	from /Users/ybakos/.rvm/gems/ruby-1.8.7-p330@test/gems/bundler-1.0.10/lib/bundler/runtime.rb:66:in `each'
	from /Users/ybakos/.rvm/gems/ruby-1.8.7-p330@test/gems/bundler-1.0.10/lib/bundler/runtime.rb:66:in `require'
	from /Users/ybakos/.rvm/gems/ruby-1.8.7-p330@test/gems/bundler-1.0.10/lib/bundler/runtime.rb:55:in `each'
	from /Users/ybakos/.rvm/gems/ruby-1.8.7-p330@test/gems/bundler-1.0.10/lib/bundler/runtime.rb:55:in `require'
	from /Users/ybakos/.rvm/gems/ruby-1.8.7-p330@test/gems/bundler-1.0.10/lib/bundler.rb:120:in `require'
	from /Users/ybakos/tmp/sftest02/config/application.rb:7
	from /Users/ybakos/.rvm/gems/ruby-1.8.7-p330@test/gems/railties-3.0.4/lib/rails/commands.rb:21:in `require'
	from /Users/ybakos/.rvm/gems/ruby-1.8.7-p330@test/gems/railties-3.0.4/lib/rails/commands.rb:21
	from script/rails:6:in `require'
	from script/rails:6

 

If anyone has successfully created a skeletal Rails 3.x app and has been able to fire up the console and execute Salesforce::SfBase.query_by_sql("select name from Account")

 


Then please do share what steps you took, and what your Gemfile and database.yml state.

 

  • February 15, 2011
  • Like
  • 0
Hi everyone, Tried to test the integration between Salesforce.com and Ruby on Rails 3.0.3 (rubygem 1.5, ruby 1.9.2)
Content of database.yml (with proper credentials erased)
development:
    adapter: activesalesforce
    url: https://www.salesforce.com
    username: ######
    password: ######
    api_version: 20.0
test:
    adapter: activesalesforce
    url: https://www.salesforce.com
    username: #####
    password: #####
    api_version: 20.0
production:
    adapter: activesalesforce
    url: https://www.salesforce.com
    username: #####
    password: #####
    api_version: 20.0
    
salesforce-default-realm:
    adapter: activesalesforce
    url: https://www.salesforce.com
    username: #####
    password: #####
    api_version: 20.0

Then content of the gemfile file
...
gem 'rails', '3.0.3'

gem 'asf-soap-adapter', :require =>'activerecord-activesalesforce-adapter'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'sqlite3-ruby', :require => 'sqlite3'

....
Runned a bundle install against this file, then a
rails generate model Salesforce::Contact
to get access to a standard SFDC object
When I try to use the console : rails console Everything load fine, no error and then when I type
Salesforce::Contact.first
After few seconds I get this error. Any clue ?
irb(main):015:0> Salesforce::Contact.first
ActiveSalesforce::ASFError: INVALID_TYPE: sObject type 'SalesforceContact__c' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name. Please reference your WSDL or the describe call for the appropriate names.
from /usr/local/lib/ruby/gems/1.9.1/gems/asf-soap-adapter-1.1.0/lib/active_record/connection_adapters/activesalesforce_adapter.rb:665:in `get_result'
from /usr/local/lib/ruby/gems/1.9.1/gems/asf-soap-adapter-1.1.0/lib/active_record/connection_adapters/activesalesforce_adapter.rb:713:in `rescue in get_entity_def'
from /usr/local/lib/ruby/gems/1.9.1/gems/asf-soap-adapter-1.1.0/lib/active_record/connection_adapters/activesalesforce_adapter.rb:706:in `get_entity_def'
from /usr/local/lib/ruby/gems/1.9.1/gems/asf-soap-adapter-1.1.0/lib/active_record/connection_adapters/activesalesforce_adapter.rb:868:in `lookup'
from /usr/local/lib/ruby/gems/1.9.1/gems/asf-soap-adapter-1.1.0/lib/active_record/connection_adapters/activesalesforce_adapter.rb:329:in `select_all'
from /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_record/base.rb:467:in `find_by_sql'
from /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_record/relation.rb:64:in `to_a'
from /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_record/relation/finder_methods.rb:333:in `find_first'
from /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_record/relation/finder_methods.rb:122:in `first'
from /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_record/base.rb:439:in `first'
from (irb):15
from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/commands/console.rb:44:in `start'
from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/commands/console.rb:8:in `start'
from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/commands.rb:23:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Tried also with a custom object called Test1, generated also the model and I get this
irb(main):016:0> Salesforce::Test1.first
ActiveSalesforce::ASFError: MALFORMED_QUERY: \nSELECT  Test1__c.* FROM Test1__c LIMIT 1\n                ^\nERROR at Row:1:Column:17\nunexpected token: '*'
from /usr/local/lib/ruby/gems/1.9.1/gems/asf-soap-adapter-1.1.0/lib/active_record/connection_adapters/activesalesforce_adapter.rb:665:in `get_result'
from /usr/local/lib/ruby/gems/1.9.1/gems/asf-soap-adapter-1.1.0/lib/active_record/connection_adapters/activesalesforce_adapter.rb:384:in `select_all'
from /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_record/base.rb:467:in `find_by_sql'
from /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_record/relation.rb:64:in `to_a'
from /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_record/relation/finder_methods.rb:333:in `find_first'
from /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_record/relation/finder_methods.rb:122:in `first'
from /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_record/base.rb:439:in `first'
from (irb):16
from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/commands/console.rb:44:in `start'
from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/commands/console.rb:8:in `start'
from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/commands.rb:23:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Thanks in advance
For information here is the list of gems when I try to list them, what is weird is that I can't see the activerecord-activesalesforce-adapter gem even though it is listed in the Gemfile
Using rake (0.8.7) 
Using abstract (1.0.0) 
Using activesupport (3.0.3) 
Using builder (2.1.2) 
Using i18n (0.5.0) 
Using activemodel (3.0.3) 
Using erubis (2.6.6) 
Using rack (1.2.1) 
Using rack-mount (0.6.13) 
Using rack-test (0.5.7) 
Using tzinfo (0.3.24) 
Using actionpack (3.0.3) 
Using mime-types (1.16) 
Using polyglot (0.3.1) 
Using treetop (1.4.9) 
Using mail (2.2.15) 
Using actionmailer (3.0.3) 
Using arel (2.0.7) 
Using activerecord (3.0.3) 
Using activeresource (3.0.3) 
Using facets (2.8.4) 
Using hpricot (0.8.3) 
Using oauth (0.4.4) 
Using rforce (0.6) 
Using asf-soap-adapter (1.1.0) 
Using bundler (1.0.10) 
Using thor (0.14.6) 
Using railties (3.0.3) 
Using rails (3.0.3) 
Using sqlite3 (1.3.3) 
Using sqlite3-ruby (1.3.3)