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!

Create an Account

Sign up to track your progress, earn points, and compete with others. Your solutions will be saved automatically.

Create account

How 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.