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)
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 accountHow 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
Contest Alert
Contest runs January 1 - 31. Complete challenges to climb the leaderboard!
Points are calculated for challenges completed during the contest period.