Skip to main content

Code Examples

Explore practical guides and implementation patterns for this topic.

Posts

Apex Development

Demystifying JSON.deserializeUntyped in Apex Salesforce with Code Examples

In plain words: When working with API responses in Salesforce, use JSON.deserialize(jsonString, YourClass.class) if you know the exact structure of the incoming data. This gives you a structured Apex object so you can access data easily (e.g., user.email ). Use JSON.deserializeUntyped(jsonString) if the data structure changes dynamically or you only need a few specific fields. This returns a generic Map or List, requiring you to cast values manually. Almost every Salesforce integration involves a common step: an external system sends you a JSON string, and you need to extract its values using Apex. Salesforce provides two primary methods to accomplish this. In this guide, we will break down both approaches with working examples, highlight common developer pitfalls, and give you a simple rule of thumb for choosing the right one.
Read article
Apex Development

Apex Full Code Examples for HTTPMock in Test Classes

💬 In plain words: JSON.deserializeUntyped parses raw JSON strings into flexible generic Apex maps ( Map<String, Object> ) or lists ( List<Object> )—eliminating the need to define predefined wrapper classes for dynamic third-party API payloads. In Salesforce development, working with JSON information is a common challenge when integrating with external systems or handling data in a flexible and dynamic way. Salesforce provides a powerful method called JSON.deserializeUntyped that allows developers to parse JSON strings into a manageable format. In this blog post, we'll explore the ins and outs of JSON.deserializeUntyped in Apex, understand its usage, and provide practical code examples to demonstrate its capabilities.
Read article