This question runs in a pre-configured Salesforce environment - no personal connection required.

Write a method findCountriesByCurrency that accepts a currency code (e.g., 'USD', 'EUR') and returns a List of country names that use that currency.

Make an HTTP GET request to the REST Countries API using the endpoint https://restcountries.com/v3.1/currency/{currencyCode} where {currencyCode} is replaced with the input parameter.

The API returns an array of country objects. Each country object contains a name field with a common property that holds the country name.

If the HTTP request fails, the API returns an error, or no countries are found, return an empty list.

Example 1: Find countries using USD

List<String> countries = findCountriesByCurrency('USD');
// Returns a list that includes 'United States', 'Ecuador', 'El Salvador', etc.
// (exact list may vary, but should include United States)

Example 2: Find countries using EUR

List<String> countries = findCountriesByCurrency('EUR');
// Returns a list of European countries that use the Euro
// (includes 'Germany', 'France', 'Spain', 'Italy', etc.)

Example 3: Invalid currency code

List<String> countries = findCountriesByCurrency('INVALID');
// Returns empty list [] because the currency code does not exist
Apex Code Editor

Welcome to Lightning Challenge!

Create an Account

Sign up to track your progress, earn points, and compete with others. Your solutions will be saved automatically.

Create account

How It Works

  • • Write your solution in the code editor
  • • Connect your Salesforce org to test
  • • Submit to check if your solution passes
  • • Use hints if you get stuck

Note

You can test your code by connecting to Salesforce, but to save your progress and earn points, you'll need to create an account. Your solutions and achievements will be tracked automatically once you're logged in.