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.
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
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
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