Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Integration with salesforce.com

Integration with salesforce.com

Sharing our experiences integrating salesforce accessing its database using databasedotcom gem

Hong Sheng Wang

December 08, 2012
Tweet

Other Decks in Programming

Transcript

  1. 2 Confidential Agenda • Who is Splashtop • Personal and

    Business • Why choose Salesforce • Integration with Salesforce • Accessing data using databasedotcom gem • Lessons Learned • References • Insights 2012/12/8
  2. 3 Confidential Who is Splashtop 2012/12/8 • Splashtop’s products are

    top-selling apps on Apple App Store, Google Play, Amazon Appstore for Android and others.
  3. 7 Confidential • CRM, Sales oriented flow automation. • Web

    to Lead, Outbound messages • Apex , trigger, callout, visualforce… • SOAP, Bulk, Metadata REST API • App Exchange, partners. • Developer documentations. Why Salesforce (2/2) 2012/12/8 Sales Automation John Smith [email protected] Send welcome email to user, send notification to sales, follow up trial processes…
  4. 8 Confidential Accessing Salesforce data from Ruby • Using databasedotcom

    gem • Setup Remote Access • Authentication and Go • Lessons Learned • References • Resources • Insights 2012/12/8 Sales Automation John started trial our product!
  5. 9 Confidential Using databasedotcom gem 2012/12/8 1. Wiki Accessing Salesforce

    Data from Ruby 1. Register developer account 2. Setup Remote Access 3. Authentication 4. Modules and Name spacing 5. Ready to go client = Databasedotcom::Client.new client.authenticate client.materialize("Lead") a*“start_trial__c"] = "YES" a.save a = Lead.find_by_Email(‘[email protected]') Accessing Data from Ruby (1/5)
  6. 10 Confidential Setup Remote Access 2012/12/8 Accessing Data from Ruby

    (2/5) Server side setup Client side setup Consumer = client id = key + token
  7. 11 Confidential Authentication and Go 2012/12/8 • find_by • find_all_by

    • field_name__c • save • delete • Lead.query("CreatedDate >= 2012-10-26T00:00:00.000z") Accessing Data from Ruby (3/5) id/secret/ passwd..
  8. 13 Confidential Lessons - Exception Handling 2012/12/8 TotalRequests Limit exceeded

    • Increase quota or carefully use Uninitialized constant Lead • Materialize each time before access constant Cannot reference converted lead • Update Contact instead. No such column 'Jigsaw' on entity 'Lead • Avoid BE side fields changes Accessing Data from Ruby (5/5)
  9. 14 Confidential Reference • Resources • Splashtop (http://www.splashtop.com) • Wiki

    Accessing Salesforce Data from Ruby (http://wiki.developerforce.com/page/Accessing_Salesforce_Data_From_Ruby) • Integrating with Force.com (youtube, wiki) • Object Reference for Salesforce and Force.com • Databasedotcom (http://rubydoc.info/gems/databasedotcom) • Insights 2012/12/8
  10. 17 Confidential REST API • @client.materialize("Lead") 2012/12/8 ***** REQUEST: https://ap1.salesforce.com/services/data/v23.0/sobjects/Lead/describe

    ***** RESPONSE: Net::HTTPOK -> {"name":"Lead","fields": [{"length":18,"name":"Id", "type":"id", "defaultValue":null,"label":"Lead ID",... {"length":0, "name":"IsDeleted","type":"boolean","defaultValue":null,"label":"Deleted",... • contact = Lead.find_by_Email(‘[email protected]') ***** REQUEST: https://ap1.salesforce.com/services/data/v23.0/query?q=SELECT%20Id%2CIsDeleted%2CMasterRecordId%2 ....%20FROM%20Lead%20WHERE%20Email%20%3D%20'demo%40splashtop.com'%20LIMIT%201 ***** RESPONSE: Net::HTTPOK -> {"totalSize":1,"done":true,"records": [{"attributes":{"type":"Lead","url":"/services/data/v23.0/sobjects/Lead/00Q9000000Cd0XXXXX"}, "Id":"00Q9000000Cd0BlEAJ","IsDeleted":false,"MasterRecordId":null,"LastName":"SplashtopDemo",...}]} References – Insight (2/4)
  11. 18 Confidential Refresh Token - concept 2012/12/8 • Reason •

    Avoid exposing account password in code. • Revoke anytime without side effects. • How • Concept from Digging Deeper into OAuth 2.0 • Build-Mobile-Apps-in-the-Cloud-with-Omniauth,-Httparty-and-Force.com • Never tried - Introduction to the databasedotcom-oauth2 Gem References – Insight (3/4)
  12. 19 Confidential Refresh Token - implementation 2012/12/8 From: http://wiki.developerforce.com/images/6/68/OAuthWebServerFlow.png 1.

    Create an local demo project 2. Gemfile ‘omniauth’ 3. Server side ‘Remote Access’ https://localhost:3000/auth/forcedotcom/callback 4. add /config/initializers/omniauth.rb 5. add /app/controllers/session_controller.rb 6. modify config/routes.rb 7. add lib/configforcedotcom.rb 8. add https 9. patch file (/Library/Ruby/Gems/1.8) ‘~/gems/oa-oauth-0.2.0/lib/omniauth/strategies/oauth2.rb’ # line 66: @access_token = build_access_token puts "access_token: #{@access_token.inspect}" 10. trigger by: https://localhost:3000/auth/forcedotcom References – Insight (4/4)