📣 Attention Salesforce Certified Trailblazers! Link your Trailhead and Webassessor accounts and maintain your credentials by December 14th. Learn more.
close
trailhead

Register an External Service

Learning Objectives

After completing this unit, you’ll be able to:

  • Define a Named Credential for your external service.
  • Register an external service using the External Services registration process.
  • 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

A named credential provided by the external service provider specifies the URL of a callout endpoint and its required authentication parameters. This description probably sounds familiar. In the last unit, we said that schemas contain the endpoint information and authentication parameters for the REST-based API web services. Let’s go ahead and define a named credential for our org. Go ahead and try it in your Trailhead Playground.
  1. From Setup, enter Named Credentials in the Quick Find box, then select Named Credentials.
  2. Click New Named Credential.
  3. For Label, use Bank.
  4. For URL, use https://th-external-services.herokuapp.com.
  5. Leave other fields as they are and click Save.
One other item of easy (but important!) housekeeping we need to take care of is to authorize the endpoint access. This is a quick process, but ensures that any callouts made from your org are approved and aren’t blocked.
  1. From Setup, enter Remote Site Settings in the Quick Find box, then select Remote Site Settings.
  2. Click New Remote Site.
  3. For Remote Site Name, use BankService (no space).
  4. Enter the URL https://th-external-services.herokuapp.com.
  5. Click Save to finish.

Use the Wizard to Register Your External Service

Now we get to register the service. Because we already did the heavy lifting, this part is simple.
  1. From Setup, enter External Services in the Quick Find box, then select External Services.
  2. Click Register New External Service and click Next.
  3. For Service Name, use BankService (no space).
  4. For Choose an Existing Named Credential, select Bank.
  5. Select Provide Complete Schema. From https://th-external-services.herokuapp.com/accounts/schema, copy in the schema information:
    A screen shot of the schema.
  6. Click Save & Next.
A list of your Apex actions appears. You can use the scrollbar to view them all.
Apex actions visible in the External Services wizard.
These actions are now available to you in Flow. We’ll create a simple flow in the next unit and show you how to find the actions in the Flow palette. For now, let’s look at the getAccount method and some of its parameters.
  • 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.
If you’ve been with us since unit one, we’ve now covered the first four steps discussed in that unit:
  1. An external services provider such, as a bank, shares their REST-based API schema specification: We got this information from our fictional bank.
  2. 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.
  3. 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.
  4. 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.
retargeting