External services have been a Salesforce platform feature for a while now. Over the past few releases, the Salesforce team has significantly improved its adoption and overall usability.
One such feature is the ability to reference external services in Apex, which can be very useful for Salesforce Developers.
External services abstract the complexity of integrating with external systems by providing a standardized way to define and interact with external APIs. It eliminates the need to manually write boilerplate code for handling HTTP request and response requests, authentication logic, and parsing responses.
You can quickly create integrations by importing the external service's OpenAPI (formerly known as Swagger) specification. Salesforce generates Apex classes and methods based on the API specification, allowing you to invoke the external service easily.
External services generate reusable Apex classes that encapsulate the external service's API operations. These generated classes can be used across multiple parts of your Apex codebase, promoting code reusability and reducing redundancy.
When the API specification of the external service changes, you can update the external service definition in Salesforce, regenerate the Apex classes, and ensure that your code is synchronized with the latest API changes. This simplifies the maintenance process and keeps your integrations up to date.
External services can also be called directly via Salesforce Flow, making them usable for Salesforce Admins and Consultants.
Say, you registered an external service named “OpenLibrary,” and this service allows you to get a list of books using the method “getBooks().”
For example, let’s get a list of books using Apex.
ExternalService.OpenLibrary api = new ExternalService.OpenLibrary(); // add a new Request object ExternalService.OpenLibrary.getBooks_Request request = new ExternalService.OpenLibrary.getBooks_Request(); /* * You can set request params if there are any. * For example, * request.pageSize = 10; */ ExternalService.OpenLibrary.getBooks_Response response = api.getBooks(request);
By leveraging this feature, developers can:
Moreover, external services empower Salesforce Administrators and Consultants by enabling them to directly call external services via Flow, expanding the range of use cases where external services can be leveraged within the Salesforce platform.