designing custom rest and soap interfaces on force.com
DESCRIPTION
Join us as we cover some of the use cases and design patterns for developing custom REST and SOAP APIs on the Force.com platform. We'll review relevant Enterprise Integration patterns, walk through real-world examples for Mobile and System-to-System integrations that require custom APIs and best practices for building your own.TRANSCRIPT
Designing custom REST and SOAP interfaces on Force.comSteven Herod, Technical Director (Australia), Cloud Sherpas@sherod
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.
Steven HerodTechnical Director, Cloud Sherpas (Australia)@sherod
Agenda• Use cases for custom interfaces• Upsides and downsides• Code walkthrough• Best Practices
3 (example) use cases• Multiple external parties need to log leads w/o duplicates
• Concern: Complex business requirements, or to understand Salesforce.
• A complex business process now needs to be exposed• Concern: Uncontrolled modification to underlying data could cause
havoc.
• Your mobile app needs to deal with a complex data model• Concern: A lot of network traffic, complex business logic
Benefits• Transaction safety – update multiple objects in a single request• Lower latency - complete many activities in a single request• Offers a narrow, service oriented, interface that allows you to
expose only the aspects of the business logic and data model that are needed.
• More robust as it can be unit tested.• A published and controlled interface specific to your business.
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
• You have the request limits for you.• Request size (3MB)• SOQL query limits (100 per request)• Record modification limits(10,000 records touched)
For and against
A real life examplePublic Internet user clicks this button on a HerokuBased website or a Mobile app
Salesforce needs to do this
Class structure
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…
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
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’s name it’s usage as a public interface • Consider the error feedback
• What does a API consumer see if things go wrong?
• Program defensively• Expect bad input
REST Specific query 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)