In this blog, we will learn the External Services in Salesforce.
External Services in Salesforce is a feature that allows you to connect Salesforce with external systems, such as REST APIs and services using a no-code/low-code approach.
Steps to integrate the external systems using External Services Feature:
- Prepare OpenAPI Specification:
- Obtain or create the OpenAPI 2.0 definition file for the external service you wish to connect to.
- This file, in JSON format, outlines the API’s structure, including its endpoints, operations, parameters, and response formats.
- Create Named Credentials:
- Configure Named Credentials to securely store the authentication information for the external API.
- The Named Credential defines the authentication method Salesforce will use when making API calls (e.g., Basic Authentication, OAuth 2.0).
- Associate the Named Credential with the External Service configuration.
- Register the External Service:
- In Salesforce Setup, navigate to External Services.
- Provide the information, Upload the OpenAPI Specification file or paste the OpenAPI Schema Definition.
- Salesforce automatically parses the OpenAPI definition, registers the service, and generates invocable actions for each operation specified in the API.
- Use invocable action in Flow or Apex:
- Set up the flow by providing the required parameters to the action, such as the inputs needed by the external API.
Here we will use a sample banking web service provided by Salesforce, which is available at this link : https://th-external-services.herokuapp.com/accounts/schema and using External Services how to access the services in our salesforce org.
Step 1: Create Named credentials for authentication.
- Go to Setup -> Quick Find -> Search for “Named Credentials” -> Click on Named Credentials.
- Click on “New Legacy” from the “New” button dropdown menu.
- Enter label, Name, URL. [endpoint: https://th-external-services.herokuapp.com]
- Click on Save button.
Step 2 : Register an External Service.
- Go to Setup -> Quick Find -> Search for “External Services” -> Click on “External Services”
- Click on “Add an External Service” button. It will show “Select an API Source” page, Select “From API Specification” option and click on next button.
- Enter “External Service Name”, “Description”. Select “Service Schema” as “Relative URL” and select the created named credential.
- For URL, enter “/accounts/schema”.
After entering all the required information, the external service retrieves the API details and presents them in Swagger JSON format, providing comprehensive information about the API and its parameters.
Click on Save and Next button
- After reviewing the Swagger, click “Next” to view the options below, where you can explore the available API operations along with their input and output parameters.
- Upon clicking “Next,” you will see that several Apex classes have been generated, which can be utilized in flows, Apex calls etc.
- After clicking “Finish,” an external service will be created, displaying additional details such as Active Operations, Total Operations, Active Objects, Total Objects, and Credentials. You can also view the available external services and objects.
The “View” action displays the available methods. [Navigation : Go to Setup -> Quick Find -> Search for “External Services” -> Click “External Services” -> Click on Action Dropmenu -> Click on “View Actions”]
The “More Details” action provides comprehensive information about the methods. [ Navigation : Go to Setup -> Quick Find -> Search for “External Services” -> Click “External Services” -> Click on Action dropmenu -> Click on “View Actions” -> Click on Action Dropmenu -> Click on “More Details”]
Step 3: Create flow to call external services.
Here is a flow which get account name from the user and retrieve the account details by passing the account name as parameter to the External API.
- Go to Setup -> Quick find -> Search for “Flows” -> Click on “Flows”.
- Click on “New Flow” button. Select “Start from Scratch” and click on “Next” button.
- Select “Screen Flow” type and click on “Create” button.
- Add screen element, Give label and Api name for the screen element.
- Drag the text component from components tab, Give label for the input text box.
- After screen element, add Action element.
- In search box , type the name of external service which we have created. [Example : TestBankService]. Select the operation. In this example, we are working the “Get Account” operation.
- Give label, Api name. In section “Set Input Values for the Selected Action”, Set the Account Name value by selecting the account name value from the screen component.
- In “show advanced options” section, check the “Manually assign variables” checkbox. To store the output , we need to create a variable.
How to create variable to store output values :
- Click on “200” textbox, it will show “New Resource”. Click on “New Resource”.
- Select “Resource Type” as
- Enter Api Name, Description.
- Select Data type as “Apex-Defined”.
- Select Apex class. For this example : Select “ExternalService__TestBankService_accountDetails”.
- Select “Available for input”, “Available for output” checkboxes. Click on “Done” button.
This is the way to create a variable to store the output value.
- After action element add screen component to display the retrieved account details:
Check whether the flow is running properly or not:
- Click on “Debug” button in flow layout.
- Enter “Account Name” [Example : Thompson ] and click on “Next” button.
- It will display the account details and right side; it will display the debug details.
After invoking the external API, we receive the response below, which will be used to display the account details on the flow screen.
Here are some real-world scenarios where External Services can be leveraged effectively:
- Credit scoring service.
- Real-Time Weather Updates
- Eligibility verification service
- Digital Payment services
- Mapping services with visualization tools
- Real-time order notification in Slack.