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.
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