16
Follow us @forcedotcom Integrating Force.com with Heroku Force.com Developer Meetup – Washington, DC August 8 2012 Pat Patterson Principal Developer Evangelist @metadaddy

Integrating Force.com with Heroku

Embed Size (px)

DESCRIPTION

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

Citation preview

Page 1: Integrating Force.com with Heroku

Follow us @forcedotcom

Integrating Force.com with HerokuForce.com Developer Meetup – Washington, DC August 8 2012

Pat PattersonPrincipal Developer Evangelist@metadaddy

Page 2: Integrating Force.com with Heroku

Safe harbor statement under the Private Securities Litigation Reform Act of 1995: This presentation may contain forward-looking statements that involve risks, uncertainties, and assumptions. If any such uncertainties 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. All statements other than statements of historical fact could be deemed forward-looking, including any projections of subscriber growth, earnings, revenues, or other financial items and any statements regarding strategies or plans of management for future operations, statements of belief, any statements concerning new, planned, or upgraded services or technology developments and customer contracts or use of our services.

The risks and uncertainties referred to above include – but are not limited to – risks associated with developing and delivering new functionality for our service, our new business model, our past operating losses, possible fluctuations in our operating results and rate of growth, interruptions or delays in our Web hosting, breach of our security measures, risks associated with possible mergers and acquisitions, the immature 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 customer deployment, our limited history reselling non-salesforce.com products, and utilization and selling to larger enterprise customers. Further information on potential factors that could affect the financial results of salesforce.com, inc. is included in our annual report on Form 10-K for the most recent fiscal year ended January 31, 2012. This document and others are available on the SEC Filings section of the Investor Information section of our Web site.

Any unreleased services or features referenced in this or other press releases or public statements are not currently available and may not be delivered on time or at all. Customers who purchase our services should make 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.

Safe Harbor

Page 3: Integrating Force.com with Heroku

Follow us @forcedotcom

Agenda

Force.com app -> Web Service

External app -> Force.com

Heroku Postgres Data ClipsNEW!!!

NEW!!!

Page 4: Integrating Force.com with Heroku

Follow us @forcedotcom

Calling Web Services from Force.com

Force.com app External System

REST/SOAP Request

REST/SOAP Response

Page 5: Integrating Force.com with Heroku

Follow us @forcedotcom

Interactive Context

For example, user presses custom button– Call web service synchronously from controller

// Create jsonString, then...

HttpRequest req = 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)

Page 6: Integrating Force.com with Heroku

Follow us @forcedotcom

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) { // ...}

Page 7: Integrating Force.com with Heroku

Follow us @forcedotcom

Calling Force.com from External Apps

Force.com app External System

REST/SOAP Request

REST/SOAP Response

Page 8: Integrating Force.com with Heroku

Follow us @forcedotcom

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

Page 9: Integrating Force.com with Heroku

Follow us @forcedotcom

Accessible From Any Environment

$ curl -H 'X-PrettyPrint: 1’ -H 'Authorization: Bearer XXX' https://na1.salesforce.com/services/data/v25.0/sobjects/Invoice_Statement__c/a015000000W5a5YAAR

{

"attributes" : {

"type" : "Invoice_Statement__c",

"url" : "/services/data/v25.0/sobjects/Invoice_Statement__c/a015000000W5a5YAAR"

},

"Id" : "a015000000W5a5YAAR",

"OwnerId" : "00550000001fg5OAAQ",

Page 10: Integrating Force.com with Heroku

Follow us @forcedotcom

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);

Page 11: Integrating Force.com with Heroku

Follow us @forcedotcom

Apex REST Methods

Insert/update many records in a single transaction

@RestResource(urlMapping='/Invoice/*')

global class QuickInvoiceService {

@HttpPost

global static String createInvoiceAndItem(String description, String merchId, Integer units) {

// Create invoice and line item records

// Either both are created or neither

}

Page 12: Integrating Force.com with Heroku

Follow us @forcedotcom

Heroku Postgres Data Clips

HTML, JSON, CSV, YAML representations of a SQL

QuerySELECT

"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

NEW!!!

Page 13: Integrating Force.com with Heroku

Follow us @forcedotcom

Integrating Data Clips with Force.com

Just another REST call to retrieve JSON data…

Define Apex Class to model datapublic class DroneFactor {

public String character_name;

public String letter_count;

public String paragraph_count;

public String drone_factor;

public static DroneFactor parse(String json) {

return (DroneFactor) System.JSON.deserialize(json, DroneFactor.class);

}

}

Page 14: Integrating Force.com with Heroku

Follow us @forcedotcom

Integrating Data Clips with Force.com

Write client to retrieve JSONpublic class DroneFactorClient {

public static List<DroneFactor> get() {

HttpRequest req = new HttpRequest();

req.setEndpoint('https://postgres.heroku.com/dataclips/ljfeywbwtxbcabardaxvcstjyodi.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);

}

}

Page 15: Integrating Force.com with Heroku

Follow us @forcedotcom

Resources

Force.com Integration Workbookhttp://wiki.developerforce.com/page/Force.com_workbook#Force.com_Integration_Workbook

Force.com REST API Connectorhttps://github.com/jesperfj/force-rest-api

Integrating Force.com and Heroku Postgres with Data

Clipshttp://blogs.developerforce.com/developer-relations/2012/08/integrating-force-com-and-heroku-postgres-with-data-

clips.html

Page 16: Integrating Force.com with Heroku

Follow us @forcedotcom

@metadaddy

Q&A