Integrating with Heroku


Published on

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

Published in: Technology
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Integrating with Heroku

  1. 1. Integrating with Developer Meetup – Washington, DC August 8 2012Pat PattersonPrincipal Developer Evangelist@metadaddy Follow us @forcedotcom
  2. 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, 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 products, and utilization and selling to largerenterprise customers. Further information on potential factors that could affect the financial results, 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., inc.assumes no obligation and does not intend to update these forward-looking statements.
  3. 3. Agenda NEW!!! app ->Web Service External app -> NEW!!! HerokuPostgres Data Clips Follow us @forcedotcom
  4. 4. Calling Web Services from REST/SOAP Request REST/SOAP Response app External System Follow us @forcedotcom
  5. 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(; 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. 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. 7. Calling from External Apps REST/SOAP Request REST/SOAP Response app External System Follow us @forcedotcom
  8. 8. REST API  Record-oriented REST API – Invoke HTTP POST/GET/PATCH/DELETE on URLs – 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. 9. Accessible From Any Environment $ curl -H X-PrettyPrint: 1’ -H Authorization: Bearer XXX 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. 10. REST API Connector  Lightweight Java library –  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. 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. 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” Follow us @forcedotcom
  13. 13. Integrating Data Clips with  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. 14. Integrating Data Clips with  Write client to retrieve JSON public class DroneFactorClient { public static List<DroneFactor> get() { HttpRequestreq = new HttpRequest(); req.setEndpoint( 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. 15. Resources Integration Workbook Workbook Force.comREST API Connector Integrating and HerokuPostgres with Data Clips force-com-and-heroku-postgres-with-data-clips.html Follow us @forcedotcom
  16. 16. Q&A@metadaddyFollow us @forcedotcom