Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Integrating Force.com with Heroku
1. Integrating Force.com with Heroku
Force.com Developer Meetup – Washington, DC August 8 2012
Pat Patterson
Principal Developer Evangelist
@metadaddy
Follow us @forcedotcom
2. Safe Harbor
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.
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
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