Register an External Service
After completing this unit, you’ll be able to:
- Define a Named Credential for your external service.
- Add an external service using a provided schema.
- Explain how the Apex actions relate to the schema you use.
Prerequisites: Named Credentials and Endpoint Access
Like many things in life, before we move forward we have to complete some prerequisites. In the past unit, we covered some detail about schemas used for External Services, since we need a usable schema before doing anything else. We didn’t talk much about Named Credentials, though. That’s OK, because this takes only a minute
- From Setup, enter Named Credentials in the Quick Find box, then select Named Credentials.
- Click New Named Credential.
- For Label, use Bank.
- For URL, use https://th-external-services.herokuapp.com.
- Leave other fields as they are and click Save.
- From Setup, enter Remote Site Settings in the Quick Find box, then select Remote Site Settings.
- Click New Remote Site.
- For Remote Site Name, use BankService (no space).
- Enter the URL https://th-external-services.herokuapp.com.
- Click Save to finish.
Use the Wizard to Register Your External Service
- From Setup, enter External Services in the Quick Find box, then select External Services.
- Click Add an External Service.
- For External Service Name, use BankService (no space).
- For Select a Named Credential, select Bank.
- Select Service Schema Complete JSON. From https://th-external-services.herokuapp.com/accounts/schema, copy in the
- Click Save.
- The getAccount method retrieves account information.
- The accountName parameter specifies the account.
- There are several output parameters for the getAccount method, too. The codes, such as id_200, correlate to specific response codes defined in the schema. You can also see these definitions nicely formatted in the Swagger Editor when you validated the schema.
- An external services provider such, as a bank, shares their REST-based API schema specification: We got this information from our fictional bank.
- Based on the specification, a developer (or maybe even you) creates a JSON-based schema definition that describes the API: While we didn’t create this schema ourselves, we reviewed the elements of a schema and the requirements for a good one. When you work with external services, you or your developer can define the schema you need for your use case.
- A Salesforce administrator declaratively creates a named credential to authenticate to the service’s endpoint using the URL provided by the external service provider: We defined our named credential, https://th-external-services.herokuapp.com.
- A Salesforce administrator declaratively registers the service and uses both the schema definition and named credential during the registration process: We just registered our first external service and looked at the generated Apex actions in the wizard.