This question runs in a pre-configured Salesforce environment - no personal connection required.
Create a method that fetches user information from the DummyJSON API by user ID and returns a Map containing the user's first name, last name, and email. The API endpoint is https://dummyjson.com/users/{id} and is already configured in remote site settings.
Method Signature:
public static Map<String, String> getUserInfo(Integer userId)
Parameters:
userId(Integer): The user ID to fetch (1-30 are valid IDs in DummyJSON)
Returns:
- Map<String, String> with keys 'firstName', 'lastName', and 'email'
- Empty Map if the request fails or user ID is invalid
Examples:
Input: userId = 1
Output: {'firstName' => 'Emily', 'lastName' => 'Johnson', 'email' => 'emily.johnson@x.dummyjson.com'}
Explanation: Returns user information for user ID 1
Input: userId = 5
Output: {'firstName' => 'Emma', 'lastName' => 'Miller', 'email' => 'emma.miller@x.dummyjson.com'}
Explanation: Returns user information for user ID 5
Input: userId = 999
Output: {}
Explanation: Returns empty Map for invalid user ID
Input: userId = null
Output: {}
Explanation: Returns empty Map for null input
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.