It took me too many hours to set up Salesforce and then use RForce to verify that Ruby could communicate w/ the Salesforce application. Hopefully the distillation that follows here will help pave the way for others. I explain very little "why"; but being able to see something "that works" may be helpful to your understanding.
Preconditions
- You have no Salesforce account.
- You have not installed RForce
- You have Ruby 1.8.7 installed and am reasonably Ruby-fluent.
- Create a developer Salesforce account and verify there is data entered into it.
- Grab the RForce gem.
- Write an unit test to retrieve data from the Salesforce account that was set up.
Detailed Steps
Create a Salesforce Developers Account
You will need an email account:
- Browse http://www.salesforce.com/platform/developers.jsp
- In the middle of the screen:
click the large button to the right, "get started".
- Fill in the requested information and submit.
- After a minute or two, check the email account you submitted for an email titled: "Salesforce login confirmation" from info@sforce.com. Open the email up and click the link supplied to confirm your developer registration and to log in.
- The login page will require you to change your password. Do so and submit.
- The developer landing page will appear (top-left corner shown here):
- At this point, you have just created your own "sandbox" CRM application. Add a record (that we will later retrieve from Ruby) by clicking the Home tab. Your home form will appear:
- In the upper-left corner to the right of the Start Here tab, click the tab.
- Click the Accounts link.
- Set the dropdown labeled View to "All Accounts" and click Go.
- You should see a list of accounts. We're going to pick one to retrieve: sForce. Hence, record the following information for it:
Column Name Value Account Name sForce Phone (415) 901-7000 - Finally, you're gonna need to set up a security token. At the very top of the same page, click the link Setup. You should see your Personal Setup page.
- In this part of the page:
click the (magic) link Reset your security token. - A page, Reset Security Token, will appear. Click the button Reset Security Token.
- A page will appear indicating that the security token has been sent to your email address.
- Wait for the email to arrive at your mailbox. It will be titled Salesforce security token confirmation. The token will appear after "Security Token:". Copy it and save it in a safe place.
Install RForce
Use Ruby gem to install RForce. The command is:
gem install rforce
(Don't forget the sudo if you are on the Macintosh.)
Create Test in Test::Unit
Copy the following unit test code into your favorite text editor:
require 'test/unit'
require 'rubygems'
gem 'rforce'
require 'rforce'
include RForce
class RforceRetrievalTest < Test::Unit::TestCase
def setup
@binding = RForce::Binding.new 'https://login.salesforce.com/services/Soap/u/16.0'
userID = 'yourID' # replace w/ your actual Salesforce developer user ID.
password = 'password' # replace w/ your Salesforce developer account password.
securityToken = 'token' # replace w/ your security token
@binding.login userID, (password + securityToken)
end
def test_retrieve_an_account
answer = @binding.search :searchString => "find {sForce} in name fields returning account(id, phone)"
record = answer[:searchResponse][:result][:searchRecords][:record]
assert_equal 'Account', record[:type]
assert_equal '(415) 901-7000', record[:Phone]
end
end
Put this file where your unit test files belong in a Ruby project, run it, and verify that you can retrieve data from your new Salesforce application.
Enjoy!
Speakin' of old farts.....
ReplyDeletehttp://www.youtube.com/watch?v=RgdffzvoVmc
Oh man. I have three cats who are fortunately gastronomically "quiet". But I had one before that could really cut loose. There are few things as disgusting as the aroma of kitty farts.
ReplyDeleteVery funny video. What did you use to create it?
Hey Scott! this is a very helpful about Salesforce!
ReplyDeletePlease keep it up!
Very nice post it's contains a bunch of great tips on salesforce help related stuff.
ReplyDelete