+ Start a Discussion
John SiedlickiJohn Siedlicki 

Repeated use of SID authentication fails with Rails using ASF

I am creating a Rails app that is called from a custom link in sfdc using SID authentication. The first time the link is clicked it works, each time after it fails giving the following error (abbreviated).
ActiveRecord::ConnectionNotEstablished: Retrieving metadata for ...)
If I change over to a hard coded login, using an entry in the database.yml file, it works every time. The error can be easily recreated with this simple rails app.
From a command line execute the following:
  1. rails sid_test
  2. cd sid_test
  3. Add require_gem 'activesalesforce' to the environment.rb file
  4. ruby script/generate model Account
  5. ruby script/generate controller Test sid_test
  6. Add this code to the sid_test method of the Test controller (uses SID authentication):
      Account.establish_connection(:adapter => 'activesalesforce',
                                   :sid => params[:sid],
                                   :url => params[:api_server_url])
      account = Account.find(:first)
      render :text => "Name = #{account.name}"
  7. ruby script/server
  8. Create a custom link in sfdc like this one:
  9. Click it once, it works, try it again, (boom)!

My assumption is that I must call establish_connection each time I need to connect to sfdc to ensure I am connecting using the proper user's session.

Any one else having these or similar issues with SID authentication?

I am using the latest versions of Rails (1.2.1), ActiveRecord (1.15.1) and ActiveSalesforce (1.1.0).  I can provide more details if it will help.


I believe ASF uses the partner API, so you need to use the Partner URL merge field, not the enterprise one.
John SiedlickiJohn Siedlicki


I tried both the Partner and Enterprise URL merge field, same result.  I'm hoping Doug Chasman has a trick to explain this weird behavior.

Thanks anyway.

are you passing the sid to a different IP address?  If so, do you have the security feature enabled to lock sessions
 to the original IP?  If so, that could be causing you problems too.
John SiedlickiJohn Siedlicki

I do have the security feature to lock sessions checked, but I am not passing the SID to different IP's (everything is on my local machine).  Just to be sure I did try it with and without the security setting checked and it gave the same results.

This appears to be a bug in ASF (unless I am using it wrong).  But you can see the code above is only two lines (step 6), I don't think it is anything with the code.

I am hoping the ASF developers can replicate the problem with the simple sample provided.  It is always easier to trouble shoot something when you have a concrete example that is easy to replicate.


Doug ChasmanDoug Chasman
Sorry John - I have not had a chance to research this yet (your repro test case should help speed that process up thanks!). We'll look into it.
John SiedlickiJohn Siedlicki

Thanks Doug.  I was hoping a simple example with no application code in the way would help!  Looking over the code I posted, it can all be cut and pasted to work with the exception of setting up your custom link in SFDC.


John SiedlickiJohn Siedlicki

Any update on this issue?  Have you been able to reproduce the problem?


Doug ChasmanDoug Chasman

I finally managed to get a chance to look at this - very easy to repro as you expected - and I am looking for a solution now.

Doug ChasmanDoug Chasman
ActiveSalesforce 1.1.4 (just published) contains the fix for this problem
John SiedlickiJohn Siedlicki

Thank you Doug.  I'll check it out right now!


John Siedlicki