This question runs in a pre-configured Salesforce environment - no personal connection required.
Attempt to fetch from an incorrect DummyJSON endpoint and handle 404 error gracefully. When the API returns a 404 status code for a non-existent product, return a structured error map containing the status, status code, and an appropriate message.
Use the DummyJSON API to fetch a product that does not exist. The method should return a map with error details when the API call fails with a 404 status code.
Examples:
Input: productId = 9999
Output: {'status': 'error', 'statusCode': 404, 'message': 'Product not found'}
Explanation: Product ID 9999 does not exist, so return structured error response
Input: productId = 1
Output: {'id': 1, 'title': 'iPhone 9', 'description': '...', ...}
Explanation: Product ID 1 exists, so return actual product data
Input: productId = null
Output: {'status': 'error', 'statusCode': 400, 'message': 'Invalid product ID'}
Explanation: Null input should return bad request 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.