This question runs in a pre-configured Salesforce environment - no personal connection required.

Make an HTTP callout to the Star Wars API to fetch character details by ID. Return a Map containing the character name, height, and mass. If the API call fails, returns an error status code, or the characterId is invalid, return null.

The Star Wars API endpoint is: https://swapi.info/api/people/{id}

The API returns a JSON response with character details including name, height, mass, and other properties. Extract only the name, height, and mass fields and return them in a Map with keys: 'name', 'height', 'mass'.

Examples:

Input: characterId = 1 Output: {'name' => 'Luke Skywalker', 'height' => '172', 'mass' => '77'} Explanation: Fetches character with ID 1 and returns name, height, and mass Input: characterId = 4 Output: {'name' => 'Darth Vader', 'height' => '202', 'mass' => '136'} Explanation: Fetches character with ID 4 and returns name, height, and mass Input: characterId = 999 Output: null Explanation: Invalid character ID returns null
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.