Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

56 lines (30 sloc) 1.842 kb

Deprecation notice

SimpleSalesforce is no longer being maintained; you should use the new DatabaseDotCom gem from Heroku instead.

SimpleSalesforce

SimpleSalesforce allows you to interact with Salesforce.com accounts as if they were ActiveRecord databases.

Simply subclass SimpleSalesforce::SalesforceObject::Base with whatever class name you like, choose which Salesforce object type it should represent, and map whichever fields you like to your local object.

On installation, a blank salesforce.yml will be copied into RAILS_ROOT/config – ensure you fill in your username, password and security token.

Installation

script/plugin install git://github.com/survival/simple_salesforce.git

You will also need the RForce (>=0.3) gem, so if you haven’t already in environment.rb:

config.gem 'rforce'

then

rake gems:install

Setting up the model

class SalesforceContact < SimpleSalesforce::SalesforceObject::Base

  use_salesforce_object "Contact"
  map_field :first_name, :to_salesforce_field => :FirstName
  map_field :last_name, :to_salesforce_field => :LastName
  map_field :Salutation    # this is the equivalent of map_field :Salutation, :to_salesforce_field => :Salutation

end

Interacting with the model

SalesforceContact.create(:first_name => "John", :last_name => "Doe")
SalesforceContact.find_by_last_name("Doe")
SalesforceContact.find_all_by_first_name("Jo%")
SalesforceContact.find(:first)

john = SalesforceContact.find(:all, :conditions => {:first_name => "John"})
john.first_name = "Jonathan"
john.save

john.update_attributes(:last_name => "Doer")

john.destroy

Copyright © 2009 Survival International, released under the MIT license

Jump to Line
Something went wrong with that request. Please try again.