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