Pages

Thursday, August 20, 2026

Serialization vs. Deserialization: The Hidden Engine Behind Salesforce Integrations

Introduction

Every time Salesforce talks to another system — an ERP, a payment gateway, a data warehouse, or a custom microservice — data has to cross a boundary. On one side, Salesforce holds data as structured records: Accounts, Contacts, Opportunities, custom objects. On the other side, an external system holds data in its own format, often with different types, structures, and rules.

The translation that happens at that boundary is not a side detail — it is the integration. Two operations sit at the center of it: serialization and deserialization. Understood well, they turn integration from a fragile point-to-point hack into a reliable, reusable architectural pattern. Understood poorly, they become the most common source of data corruption, sync failures, and "it works on one record but not the other" bugs.

This post breaks down what these operations actually do, how they differ, and how they combine with synchronization to keep Salesforce and connected systems consistent over time.

What Is Serialization?

Serialization is the process of converting an in-memory object — say, a Salesforce Account record with its fields, relationships, and metadata — into a format that can be transmitted or stored: typically JSON, XML, or a binary format.

Think of it as packing. The object exists in a rich, structured form inside Salesforce. To send it anywhere — over an API call, into a message queue, into a file — it has to be flattened into a portable format that the receiving system can understand.

In a Salesforce context, serialization typically happens when:

  • An Apex trigger or Batch class sends record data to an external REST endpoint
  • A Platform Event or Change Data Capture (CDC) event is published
  • An outbound integration (via MuleSoft, Boomi, or custom middleware) prepares a payload for delivery
  • Data is exported through the Bulk API for external consumption

Example — Apex serializing an Account to JSON:

Account acc = [SELECT Id, Name, Industry, AnnualRevenue FROM Account LIMIT 1];
String jsonPayload = JSON.serialize(acc);
// {"Id":"001xx000003DGb2AAG","Name":"Acme Corp","Industry":"Technology","AnnualRevenue":5000000}

The object is now a portable string — ready to travel across the wire.

What Is Deserialization?

Deserialization is the reverse operation: taking that portable format and reconstructing it back into a usable object, on whichever system receives it.

Think of it as unpacking. When Salesforce receives a webhook payload from an external system, or when middleware delivers a response back into Salesforce, that raw JSON or XML has to be parsed and mapped back into an Apex object, an sObject, or a wrapper class Salesforce can actually work with.

In a Salesforce context, deserialization typically happens when:

  • An inbound REST API call delivers a JSON payload that needs to become an sObject or custom class
  • A callout response is parsed to extract values for further processing
  • A middleware platform receives data and maps it into Salesforce's object model before an upsert

Example — Apex deserializing JSON into a wrapper class:

public class AccountWrapper {
    public String Id;
    public String Name;
    public String Industry;
    public Decimal AnnualRevenue;
}

String responseBody = '{"Id":"001xx000003DGb2AAG","Name":"Acme Corp","Industry":"Technology",
"AnnualRevenue":5000000}';AccountWrapper acc = (AccountWrapper) JSON.deserialize(responseBody,
AccountWrapper.class);

The string is now a structured object again — usable, queryable, and safe to insert or update in Salesforce.



Serialization vs. Deserialization: Side by Side

Aspect Serialization Deserialization
Direction Object → Portable format Portable format → Object
Occurs when Sending data out of Salesforce Receiving data into Salesforce
Typical trigger Outbound callout, event publish, export Inbound API call, callout response, event subscription
Common formats JSON, XML, CSV, Avro Same formats, parsed back into objects
Primary risk Data loss from incomplete field mapping Type mismatches, malformed payloads, missing required fields
Salesforce tools JSON.serialize(), JSON.serializePretty(), XML DOM classes JSON.deserialize(), JSON.deserializeUntyped(), XML parsers

The two are mirror images of each other, and that symmetry matters. A field that isn't serialized correctly on the way out can never be deserialized correctly on the way in — the two operations have to be designed as a pair, not built independently by two different teams on two different systems.

Where Synchronization Fits In

Serialization and deserialization handle a single transaction: one object, converted and reconstructed. Synchronization is the larger discipline of keeping two systems consistent over time, across many such transactions, including retries, conflicts, and failures.

A synchronization layer typically has to answer questions serialization alone cannot:

  • What happens when the same record is updated on both sides at once? (conflict resolution)
  • What happens when a payload fails to deserialize halfway through a batch? (partial failure handling)
  • How often does data move — real-time, near-real-time, or scheduled batch?
  • How do we know what changed since the last sync, without resending everything? (delta detection, often via CDC or timestamps)

In Salesforce architectures, synchronization is usually implemented through one of a few patterns:

  • Real-time, event-driven sync — Platform Events or Change Data Capture push changes out immediately as they happen.
  • Near-real-time, middleware-orchestrated sync — MuleSoft, Boomi, or similar tools poll, transform, and route data on a short interval.
  • Batch sync — Scheduled Apex or the Bulk API move large volumes on a fixed schedule (nightly, hourly).

Serialization and deserialization are the mechanics inside each of these patterns; synchronization is the strategy that decides when and how those mechanics get triggered.

Why This Layer Deserves Real Design Attention

It's tempting to treat serialization and deserialization as plumbing — a technical footnote beneath the "real" integration logic. In practice, this layer is where most production incidents originate:

  • Silent field drops — a new custom field added in Salesforce that the external schema was never updated to serialize
  • Type coercion errors — a currency field arriving as a string, or a picklist value that doesn't match an expected enum
  • Null handling mismatches — a field that's optional on one side but required on the other
  • Versioning drift — a payload structure that changes on one system without a corresponding update on the other

Solving these well means treating the serialization/deserialization contract as a first-class design artifact: documented, versioned, and tested — not something that lives only inside a mapping class no one has looked at since it was written.

Visual Summary

The three diagrams below accompany this post: (1) the serialization–deserialization round trip, (2) the three synchronization architecture patterns, and (3) where failures typically concentrate in that round trip.

Closing Thoughts

Serialization and deserialization aren't glamorous, but they are foundational. Every Salesforce integration — whether it's a simple outbound webhook or a full enterprise data fabric — depends on these two operations being designed as a matched pair, with synchronization layered on top to manage consistency over time.

Treat this layer as architecture, not plumbing, and the rest of the integration tends to hold together. Treat it as an afterthought, and it becomes the layer where every hard-to-reproduce bug eventually traces back to.

Have questions about designing a specific Salesforce integration pattern — real-time events, middleware-based sync, or bulk data movement? That's a natural follow-up conversation.

No comments: