Search

Salesforce on Rails with the Databasedotcom Gem

Daniel Rice

2 min read

Feb 27, 2012

Salesforce on Rails with the Databasedotcom Gem

At Highgroove, we’re always looking for new Ruby gems to help speed up development and keep the code DRY. The gem I found this time was Heroku’s very own Databasedotcom gem, a fantastic Salesforce.com API wrapper for Ruby! I must admit, I wasn’t very surprised to find a gem since Salesforce owns Heroku, but I did not expect it to be so fantastic and easy to use. Here’s how!

There are only a few steps involved in getting the Databasedotcom gem connected to your salesforce instance and working:

  • Create a new Databasedotcom::Client instance – client = Databasedotcom::Client.new(:client_id => ENV['SALESFORCE_KEY'], :client_secret => ENV['SALESFORCE_SECRET'])
  • Authenticate with Salesforce – client.authenticate :token => SALESFORCE_OAUTH2_TOKEN, :instance_url => INSTANCE_URL, :refresh_token => SALESFORCE_REFRESH_TOKEN
  • Create a Ruby Class from a Salesforce Object – client.materialize("Contact")
  • Use the newly available Ruby class named ‘Contact’ and use ActiveRecord::Base methods on it. The gem will translate the ActiveRecord syntax into SOQL and API calls for you just like you’re used to in Rails with any other database adapter!
  • For example: Contact.find_or_create_by_FirstName_and_LastName(:FirstName => 'Daniel', :LastName => 'Rice')

There are many other ways to use this gem, and its possible to interface with custom objects and custom fields, but I wanted to mainly illustrate how few lines of code it takes to make a Salesforce integration thanks to the awesome job by the Heroku team.

To see more use cases, features, and general information about this gem, please check out the Databasedotcom gem’s README on Github.

Image Credit: Salesforce.com *No Software logo is a registered trademark of Salesforce.com

Juan Pablo Claude

Reviewer Big Nerd Ranch

During his tenure at BNR, Juan Pablo has taught bootcamps on macOS development, iOS development, Python, and Django. He has also participated in consulting projects in those areas. Juan Pablo is currently a Director of Technology focusing mainly on managing engineers and his interests include Machine Learning and Data Science.

Speak with a Nerd

Schedule a call today! Our team of Nerds are ready to help

Let's Talk

Related Posts

We are ready to discuss your needs.

Not applicable? Click here to schedule a call.

Stay in Touch WITH Big Nerd Ranch News