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

Call the REST Countries API to fetch information about a country by its name. Extract and return the country population as a Long value. Handle errors gracefully by returning null for invalid country names or failed API calls.

The API endpoint is: https://www.lightningchallenges.com/api/countries/v3.1/name/{countryName}?fields=population

The API returns a JSON array with country data. Use the first result from the array and extract the population field.

Examples:

Input: countryName = 'Germany' Output: 83491249 Explanation: Fetches Germany population from REST Countries API Input: countryName = 'Japan' Output: 123210000 Explanation: Fetches Japan population from REST Countries API Input: countryName = null Output: null Explanation: Returns null for null input Input: countryName = 'InvalidCountry' Output: null Explanation: Returns null for invalid country name (404 error)

Country data is served from a pinned REST Countries snapshot hosted by Lightning Challenges. Use https://www.lightningchallenges.com/api/countries/v3.1 instead of the retired public API; no API key is required.

Apex Code Editor

Welcome to Lightning Challenge!

How It Works

  • • Write your solution in the code editor
  • • This challenge runs without connecting your own org
  • • 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.

Wally can't hear you

Please sign in to access the AI Assistant

Sign In