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!
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
Note
You can test your code by connecting to Salesforce, but to save your progress and earn points, you'll need to create an account. Your solutions and achievements will be tracked automatically once you're logged in.