Designing custom REST and SOAP interfaces on Force.com

16
Designing custom REST and SOAP interfaces on Force.com Steven Herod, Technical Director (Australia), Cloud Sherpas @sherod

description

My Dreamforce presentation on Designing custom REST and SOAP interfaces on the force.com platform covering use cases, benefits, and best practices.

Transcript of Designing custom REST and SOAP interfaces on Force.com

Page 1: Designing custom REST and SOAP interfaces on Force.com

Designing custom REST and SOAP interfaces on Force.comDesigning custom REST and SOAP interfaces on Force.com

Steven Herod, Technical Director (Australia), Cloud Sherpas

@sherod

Page 2: Designing custom REST and SOAP interfaces on Force.com

Safe harborSafe 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 product or service availability, 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, new products and services, 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, the outcome of any litigation, risks associated with completed and any 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 and in our quarterly report on Form 10-Q for the most recent fiscal quarter. These documents and others containing important disclosures 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 presentations, 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.

Page 3: Designing custom REST and SOAP interfaces on Force.com

Steven HerodSteven Herod

Technical Director, Cloud Sherpas (Australia)

@sherod

http://limitexception.herod.net/

Technical Director, Cloud Sherpas (Australia)

@sherod

http://limitexception.herod.net/

Page 4: Designing custom REST and SOAP interfaces on Force.com

Agenda

• Use cases for custom interfaces

• Upsides and downsides

• Code walkthrough

• Best Practices

Page 5: Designing custom REST and SOAP interfaces on Force.com

3 (example) use cases

• Multiple external parties need to log leads w/o duplicates

• Concern: 3rd Party needs to understand Salesforce and your data model

semantics and logic.

• Need to interact with a complex opportunity process/data model

• Concern: An internal business process with many rules needs to be

exposed to an external system.

• Your mobile app needs to modify multiple parts of the data model to

complete an action

• Concern: ‘Chatty’ network traffic, opportunity for failures at any point.

Page 6: Designing custom REST and SOAP interfaces on Force.com

Benefits of going custom…• Transaction safety

• Update multiple objects in a single request

• Lower latency• Complete many activities in a single request

• Service Oriented • Offers a narrow/specific interface that allows you to expose only the aspects of the business

logic and data model that are needed.

• More Robust• Can unit tested.

• Controlled interface• A published and controlled interface specific to your business.

Page 7: Designing custom REST and SOAP interfaces on Force.com

Caveats• Your ETL Tool may not understand custom REST/SOAP interfaces with

Salesforce.• An out of the box ‘Salesforce Adapter’ is not applicable here.

(Generic REST / SOAP should work however)

• You need to write code (and test coverage)• What was ‘no effort’ on the Salesforce side now becomes a Software

Development process

• Limits!• Request size (3MB)• SOQL query limits (100 per request)• Record modification limits(10,000 records touched)

Page 8: Designing custom REST and SOAP interfaces on Force.com

For and against

Page 9: Designing custom REST and SOAP interfaces on Force.com

A real life examplePublic Internet user clicks this button on a HerokuBased website or a Mobile app

Salesforce needs to do this

Page 10: Designing custom REST and SOAP interfaces on Force.com

Class structure

Page 11: Designing custom REST and SOAP interfaces on Force.com

Best Practices

• Consciously design your API• Think about it! Govern it! Consider every method/operation! Document it!

• Fight for the user• Think: “What is easiest for the consumer of the interface?”

• Work with the platform• Salesforce REST != REST purist

• Salesforce SOAP != WS-*

• Consider how you will manage testing with external parties• Test data, test system availability…

Page 12: Designing custom REST and SOAP interfaces on Force.com

Best Practices • Use Apex Wrapper Classes as Data Transfer Objects

• Refrain from sending or expecting sObjects or you may expose a lot of internal details

• Use a Services layer• Keep your business code out of the class that handles the public interface.

• Bake in versioning• Consider if you need to make a change to your interface

• Unit test all the things• The unit test is your insurance and means you can detect when declarative

changes affect your code

Page 13: Designing custom REST and SOAP interfaces on Force.com

Best Practices

• Manage your transactions explicitly• Especially if you do exception trapping

• Use @future if you need to.• Shorten response times where its safe to go async

• Indicate in the Apex Class name that is a public interface

• Consider the error feedback• What does a API consumer see if things go wrong?

• Program defensively• Expect bad input

Page 14: Designing custom REST and SOAP interfaces on Force.com

Finally… REST specific advice

• 1 Class per URL mapping = proliferation

• Don’t forget the Query String

• E.g. GET /LoanApplications/?daysSinceUpdate=5

• Watch your status codes and verbs!

• Use the right status code and the right verb (GET, PUT, POST)

Beep

Page 15: Designing custom REST and SOAP interfaces on Force.com
Page 16: Designing custom REST and SOAP interfaces on Force.com