Three example use cases for custom REST and SOAP interfaces on the Force.com platform are given: 1) Allowing multiple external parties to log leads without duplicates, 2) Exposing a complex business process, and 3) Allowing a mobile app to interact with complex data models. The benefits of custom interfaces are listed as transaction safety, lower latency, and exposing only necessary business logic and data. Caveats include tools not understanding custom interfaces and the need to write and test code. Best practices discussed include conscious API design, considering the user experience, working with platform capabilities, and thorough testing.
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Design custom REST and SOAP interfaces
1. Designing custom REST and SOAP
interfaces on Force.com
Steven Herod, Technical Director (Australia), Cloud Sherpas
@sherod
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 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.
4. Agenda
• Use cases for custom interfaces
• Upsides and downsides
• Code walkthrough
• Best Practices
5. 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
6. 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.
7. 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)
14. 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…
15. 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
16. 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
17. 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)