Restforce is the most popular Ruby gem for interacting with Salesforce using the Salesforce API, downloaded over 16,000,000 times.
1. Add restforce
to your Gemfile
, then run bundle install
(or install it
manually with gem install
).
gem 'restforce', '~> 5.0.0'
The gem only supports Ruby 2.5 onwards. To use Restforce with earlier versions of Ruby, you'll need to use an earlier version of the gem.
2. Instantiate a Restforce
client object with your API
authentication details. You can use your username and password as below, or authenticate with OAuth.
# Don't commit your authentication details with your code - use environment variables <3
export SALESFORCE_USERNAME="username"
export SALESFORCE_PASSWORD="password"
export SALESFORCE_SECURITY_TOKEN="security token"
export SALESFORCE_CLIENT_ID="client id"
export SALESFORCE_CLIENT_SECRET="client secret"
export SALESFORCE_API_VERSION="38.0"
client = Restforce.new
3. Query Salesforce like a pro.
my_leads = client.query("SELECT Id, Source FROM Lead where OwnerId = 'INSERT_USER_ID_HERE'")
# => #<Restforce::Collection >
To discover all the great things you can do with Restforce, check out the README and the full documentation.
NoMethodError
when upserting an
existing record.upsert
and upsert!
mutated the provided
attributes, starts raising an error where a custom external ID field name is supplied to upsert
and upsert!
but it is missing from the provided attributes, and uses the client's configured
SSL options for authentication requests. (changelog)
upsert
ing with an ID, and relaxes the
gem's dependency on Faraday to allow upgrading it to 1.0. (changelog)
SALESFORCE_API_VERSION
environment variable. (changelog)get_deleted
method. (changelog)300
is returned due to an external ID matching multiple records for an upsert
operation. (changelog)Restforce::ServerError
when Salesforce is experiencing problems,
and improves the handling of the response body in errors. (changelog)We welcome contributions and bug reports so we can together make Restforce as great as possible 💕
We'd love to have you involved, whether it's your first open source contribution or your thousandth. To get started, see our CONTRIBUTING.md, and take note of our code of conduct.
If you have any questions, contact Tim Rogers, the maintainer.
Want help using Restforce, with contributing, or have another question?
Get in touch with Tim Rogers, the maintainer of Restforce, at tim@restforce.org.
Restforce is released under the MIT license
Page last updated 10th July 2020
© Tim Rogers and Eric J. Holmes 2020