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://restcountries.com/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: 83240525
Explanation: Fetches Germany population from REST Countries API
Input: countryName = 'Japan'
Output: 125124989
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)
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
Contest Alert
🏆 #CodeEveryDay July 2026
Contest runs July 1 - 31. Complete challenges to climb the leaderboard!
Only the 31 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.