This question runs in a pre-configured Salesforce environment - no personal connection required.
Make an HTTP GET request to the REST Countries API to retrieve the languages spoken in a given country. Use the endpoint https://restcountries.com/v3.1/name/{countryName}?fields=languages to fetch country data. Parse the JSON response and return a sorted list of language names. Return an empty list for null or blank input, if the API returns a non-200 status code, or if no languages are found.
Examples:
Input: countryName = 'Germany'
Output: ['German']
Explanation: Germany has one official language, German
Input: countryName = 'Switzerland'
Output: ['French', 'German', 'Italian', 'Romansh']
Explanation: Switzerland has four official languages, returned in alphabetical order
Input: countryName = ''
Output: []
Explanation: Blank input returns an empty list
Input: countryName = null
Output: []
Explanation: Null input returns an empty list
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.