Putting it all together

With a solid background in API principles and the ability to use the sObject, bulk, and custom API endpoints, it's possible to seamlessly integrate external data with Salesforce. While integrating into Salesforce is undoubtedly useful, it's only when coupled with calling out from Salesforce that the full power of API integrations becomes visible. The use cases are easy to imagine. For instance, a marketing mailing company may upload hundreds of thousands of contacts a day via the bulk API and process them using a batch job, which validates their mailing address via the US Postal Service's address validation API. E-commerce sites on the Salesforce1 platform can accept payment via various payment APIs and undertake order fulfillment via an integration with the company's ERP system. Google Chrome and Firefox extensions for Gmail can call in via the sObject API to let users attach e-mails from Gmail to cases, accounts, contacts, and even custom objects. You can even bridge media types using the API to drive call center phone dialers or send text messages. Any time you need to combine your Salesforce data with external data, APIs provide the easiest and often the best way to access it. Knowing which API to use and when to use it is the key to mastering their use. Let's take a look at the following diagrammatic representation of the Salesforce platform:

Putting it all together

If the integration is controlled from outside Salesforce and is largely transactional, manipulating a single or at most a few dozen records at a time, the sObject API is the simplest approach. However, if your integration relies on massive amounts of data being inserted or updated, you'll need to use the bulk API. The general threshold is 600 records. More than that, and you should use the bulk API. Under 600 records and the choice between sObject API and the bulk API is yours. If your integration is controlled from outside Salesforce and manipulates complex sets of related objects or requires custom processing inside Salesforce, custom Apex APIs are your go-to option.

On the other hand, if the API requests originate inside Salesforce, making RESTful callouts to those APIs can be done using a generic RestClient class in conjunction with an API-specific extension and some individual request and response classes as we demonstrated. These callouts can be particularly useful in conjunction with batch jobs or other asynchronous processing techniques talked about in Chapter 3, Asynchronous Apex for Fun and Profit, to accomplish bulk data-cleanliness tasks. Additionally, they're fantastic for pulling supplemental information about contacts such as tweets, Facebook posts, or Instagram photos.

Integrations are perhaps the most crucial aspect to mastering Force.com development. The Salesforce1 platform has a staggeringly powerful declarative application development environment, and an equally powerful code-based environment, but it's the data that makes these features useful to businesses big and small. Getting data into and out of the platform for use is therefore the foundation for meaningful apps. The APIs we talked about in this chapter are just the start. The streaming, analytics, metadata, tooling, and audit trail history APIs all bring additional features and capabilities to the platform, but in the end, all APIs are centered around data. Building a robust set of portable tools such as a RestClient class, makes adding new APIs into the mix a much simpler and faster affair. Practice using these integrations and tools and you'll quickly find that you've learned not only how to manipulate data, but also how to do so at scale in the right fashion with the right tools. Additionally, as you integrate systems with APIs, you'll become quite the expert at asynchronous processing, bulk data manipulation, and a host of other Force.com tools and practices. APIs are therefore not only the tools for integrating different systems, but also for integrating your knowledge of the platform into a masterful architecture.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.191.134