Your SlideShare is downloading. ×
Integrating Force.com with Heroku
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Saving this for later?

Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Text the download link to your phone

Standard text messaging rates apply

Integrating Force.com with Heroku

3,333
views

Published on

Presented at Washington, DC Force.com Developer Meetup, August 8, 2012.

Presented at Washington, DC Force.com Developer Meetup, August 8, 2012.

Published in: Technology

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
3,333
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
82
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Integrating Force.com with HerokuForce.com Developer Meetup – Washington, DC August 8 2012Pat PattersonPrincipal Developer Evangelist@metadaddy Follow us @forcedotcom
  • 2. Safe HarborSafe harbor statement under the Private Securities Litigation Reform Act of 1995: This presentation maycontain forward-looking statements that involve risks, uncertainties, and assumptions. If any suchuncertainties materialize or if any of the assumptions proves incorrect, the results of salesforce.com, inc.could differ materially from the results expressed or implied by the forward-looking statements we make. Allstatements other than statements of historical fact could be deemed forward-looking, including anyprojections of subscriber growth, earnings, revenues, or other financial items and any statements regardingstrategies or plans of management for future operations, statements of belief, any statements concerningnew, planned, or upgraded services or technology developments and customer contracts or use of ourservices.The risks and uncertainties referred to above include – but are not limited to – risks associated withdeveloping and delivering new functionality for our service, our new business model, our past operatinglosses, possible fluctuations in our operating results and rate of growth, interruptions or delays in our Webhosting, breach of our security measures, risks associated with possible mergers and acquisitions, theimmature market in which we operate, our relatively limited operating history, our ability to expand, retain,and motivate our employees and manage our growth, new releases of our service and successful customerdeployment, our limited history reselling non-salesforce.com products, and utilization and selling to largerenterprise customers. Further information on potential factors that could affect the financial results ofsalesforce.com, inc. is included in our annual report on Form 10-K for the most recent fiscal year endedJanuary 31, 2012. This document and others are available on the SEC Filings section of the InvestorInformation section of our Web site.Any unreleased services or features referenced in this or other press releases or public statements are notcurrently available and may not be delivered on time or at all. Customers who purchase our services shouldmake the purchase decisions based upon features that are currently available. Salesforce.com, inc.assumes no obligation and does not intend to update these forward-looking statements.
  • 3. Agenda NEW!!! Force.com app ->Web Service External app ->Force.com NEW!!! HerokuPostgres Data Clips Follow us @forcedotcom
  • 4. Calling Web Services from Force.com REST/SOAP Request REST/SOAP Response Force.com app External System Follow us @forcedotcom
  • 5. Interactive Context  For example, user presses custom button – Call web service synchronously from controller // Create jsonString, then... HttpRequestreq = new HttpRequest(); req.setMethod(POST); req.setEndpoint(https://webservice.herokuapp.com/order); req.setHeader(Content-Type, application/json); req.setBody(jsonString); Http http = new Http(); res = http.send(req); // Now parse response and update record(s) Follow us @forcedotcom
  • 6. Trigger Context  Synchronous callouts are not allowed! – Call web service asynchronously from trigger // In Apex Trigger, build list of ids, then... Integration.postOrder(invoiceIds); // Define asynchronous method in Apex Class @future (callout=true) public static void postOrder(List<Id>invoiceIds) { // ... } Follow us @forcedotcom
  • 7. Calling Force.com from External Apps REST/SOAP Request REST/SOAP Response Force.com app External System Follow us @forcedotcom
  • 8. Force.com REST API  Record-oriented REST API – Invoke HTTP POST/GET/PATCH/DELETE on URLs – https://na9.salesforce.com/services/data/v25.0/ sobjects/Invoice_Statement__c/a01E0000000BsAz  Query and Search Endpoints – .../v25.0/query?q=SELECT+Invoice_Value__c+FROM+ Invoice_Statement__c  Authenticate via OAuth – Interactive or username/password Follow us @forcedotcom
  • 9. Accessible From Any Environment $ curl -H X-PrettyPrint: 1’ -H Authorization: Bearer XXX https://na1.salesforce.com/services/data/v25.0/sobjects/Invoic e_Statement__c/a015000000W5a5YAAR { "attributes" : { "type" : "Invoice_Statement__c", "url" : "/services/data/v25.0/sobjects/Invoice_Statement__c/a015000000 W5a5YAAR" }, "Id" : "a015000000W5a5YAAR", "OwnerId" : "00550000001fg5OAAQ", … Follow us @forcedotcom
  • 10. Force.com REST API Connector  Lightweight Java library – https://github.com/jesperfj/force-rest-api  Includes OAuth implementations  Define model classes for standard/custom object  Easy CRUD // Set up api object from config, session, then... Account a = new Account(); a.setName("Test account"); String id = api.createSObject("account", a); a= api.getSObject("Account",id).as(Account.class); Follow us @forcedotcom
  • 11. Apex REST Methods  Insert/update many records in a single transaction @RestResource(urlMapping=/Invoice/*) global class QuickInvoiceService { @HttpPost global static String createInvoiceAndItem(String description, StringmerchId, Integer units) { // Create invoice and line item records // Either both are created or neither } Follow us @forcedotcom
  • 12. HerokuPostgres Data Clips NEW!!!  HTML, JSON, CSV, YAML representations of a SQL Query SELECT "characters"."name" AS "character_name", SUM(length("paragraphs"."plain_text")) as "letter_count", COUNT(*) as "paragraph_count", SUM(length("paragraphs"."plain_text"))/COUNT(*) as "drone_factor" FROM "paragraphs” INNER JOIN "characters" ON "paragraphs"."character_id" = "characters"."id” https://postgres.heroku.com/dataclips/ljfeywbwtxbcabardaxvcstjyodi Follow us @forcedotcom
  • 13. Integrating Data Clips with Force.com  Just another REST call to retrieve JSON data…  Define Apex Class to model data public class DroneFactor { public String character_name; public String letter_count; public String paragraph_count; public String drone_factor; public static DroneFactorparse(Stringjson) { return (DroneFactor) System.JSON.deserialize(json, DroneFactor.class); } } Follow us @forcedotcom
  • 14. Integrating Data Clips with Force.com  Write client to retrieve JSON public class DroneFactorClient { public static List<DroneFactor> get() { HttpRequestreq = new HttpRequest(); req.setEndpoint(https://postgres.heroku.com/dataclips/ljfeywbwtxbcabar daxvcstjyodi.json); req.setMethod(GET); Http http = new Http(); HTTPResponse res = http.send(req); System.debug(Data Clip response code: +res.getStatusCode()+. Status: +res.getStatus()); return (List<DroneFactor>)System.JSON.deserialize(res.getBody(), List<DroneFactor>.class); } } Follow us @forcedotcom
  • 15. Resources Force.com Integration Workbook http://wiki.developerforce.com/page/Force.com_workbook#Force.com_Integration_ Workbook Force.comREST API Connector https://github.com/jesperfj/force-rest-api Integrating Force.com and HerokuPostgres with Data Clips http://blogs.developerforce.com/developer-relations/2012/08/integrating- force-com-and-heroku-postgres-with-data-clips.html Follow us @forcedotcom
  • 16. Q&A@metadaddyFollow us @forcedotcom