Summary
We began this chapter by reviewing some of the basics of RESTful callout and looking at how we can make a simple REST call to a service. We then discussed how we must use remote site settings to enable Salesforce to make callouts to an external endpoint.
Following this, we looked at how endpoints are often secured and how we can perform authentication, firstly, by reviewing an example using HTTP Basic authentication, before then creating a named credential that handled the authentication for us. We discussed the benefits of named credentials and how they can help us produce more flexible solutions. The last section, dealing with security, was then a brief discussion on the use of a certificate to enable two-way SSL.
We then looked at how we can test callout code – notably, by first using a custom implementation of the HttpCalloutMock
interface and then through the use of the StaticResourceCalloutMock
class for large responses. When building our custom implementation...