This question runs in a pre-configured Salesforce environment - no personal connection required.
Create a method that fetches product reviews from the DummyJSON API and returns formatted review information.
Your method should:
- Make an HTTP GET request to
https://dummyjson.com/products/{productId} - Parse the JSON response to extract the
reviewsarray - Format each review as:
"{reviewerName}: {rating}/5 - {comment}" - Return a List of Strings containing all formatted reviews
- Return an empty list if the product has no reviews
- Return null if productId is null or less than 1
API Response Structure
The DummyJSON API returns a product object with a reviews array:
{
"id": 1,
"title": "Product Name",
"reviews": [
{
"rating": 4,
"comment": "Great product!",
"reviewerName": "John Doe",
"reviewerEmail": "john@example.com"
}
]
}
Examples
Example 1: Valid Product with Reviews
- Input:
productId = 1 - Output:
["Emily Johnson: 2/5 - Very unhappy with my purchase!", "Michael Smith: 4/5 - Very pleased!", "Sophia Brown: 5/5 - Highly impressed!"]
Example 2: Null Product ID
- Input:
productId = null - Output:
null
Example 3: Invalid Product ID
- Input:
productId = 0 - Output:
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 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
Contest Alert
🏆 #CodeEveryDay Feb 2026
Contest runs February 1 - 28. Complete challenges to climb the leaderboard!
Points are calculated for challenges completed during the contest period.