SF-PD2 Advanced Developer Fundamentals Practice Question
A developer is building an Apex REST service that must accept an inbound JSON payload from an external system. The external system sends an array of order records, and the developer needs the JSON keys (such as order_id) to map directly to Apex property names (such as order_id) without any manual transformation. Which approach should the developer use to deserialize the payload into Apex objects?
⚠ Common exam trap
The trap here is assuming that deserializeUntyped can be cast directly to a wrapper class, when it actually returns generic Map and List structures.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Use JSON.deserialize with a wrapper class whose properties match the JSON keys exactly.
JSON.deserialize with a wrapper class is the correct choice because Salesforce maps JSON keys to Apex property names that match exactly, including underscores. The other options either require manual mapping, produce untyped collections, or perform the opposite operation. When key names already align with Apex properties, the typed deserialize method is the most direct and maintainable solution.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Use JSON.createParser and manually read each field into the wrapper class.
Why it's wrong here
JSON.createParser is a valid streaming approach, but it requires manual token handling and field assignment. When key names already align with Apex property names, JSON.deserialize accomplishes the mapping automatically, making the parser approach unnecessarily verbose and error-prone for this scenario.
- ✓
Use JSON.deserialize with a wrapper class whose properties match the JSON keys exactly.
Why this is correct
JSON.deserialize maps JSON keys to Apex property names that match exactly, so a wrapper class with properties named order_id will deserialize correctly. This is the standard approach for strongly typed deserialization when the external JSON key names are known and align with the Apex property names the developer defines.
- ✗
Use JSONGenerator to write the payload into a wrapper instance.
Why it's wrong here
JSONGenerator serializes Apex objects into JSON output; it does not deserialize inbound JSON into Apex objects. Using it here would be the wrong direction of data flow and would not populate the wrapper class from the external payload.
- ✗
Use JSON.deserializeUntyped and then cast the resulting Map to an Apex wrapper class.
Why it's wrong here
deserializeUntyped returns generic Map<String,Object> and List<Object> structures; you cannot cast a Map directly to a custom Apex wrapper class. While you could manually iterate the Map and build wrapper instances, the question specifies the keys already match property names, so the typed deserialize is simpler and correct.
About these practice questions
This SF-PD2 question is part of Courseiva's 226-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
JA
Written and reviewed by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
Last reviewed September 2026 · checked against the official Salesforce exam blueprint
This SF-PD2 practice question is part of Courseiva's free Salesforce certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the SF-PD2 exam.