Sub topic 1
Why integration patterns matter
Most Salesforce orgs do not work alone. Orders live in an ERP, invoices live in a billing system, and customers sign in through an identity provider. Someone has to decide how these systems exchange data. This chapter explains why that decision is better made with a small set of named patterns than case by case. It also introduces the three patterns the rest of the tutorial covers.
Prerequisites
This chapter assumes you already know the following:
- The basic Salesforce data model: objects, fields, and records.
- What a REST API is, and how to read JSON.
- Basic Apex syntax, including how a trigger runs.
- HTTP methods (GET, POST, PATCH) and common status codes (200, 400, 401, 500).
You do not need hands-on integration experience. Later chapters build the code. This one builds the vocabulary and the decision habits.
What an integration pattern is
An integration pattern is a reusable answer to a recurring integration problem. It describes who starts the conversation, whether the sender waits for a reply, how much data moves at once, and what happens when something fails. It does not name a product. The same pattern can be built with different Salesforce features, and one feature can serve more than one pattern.
Patterns give a team shared language. "We need request-reply here" tells everyone the caller blocks on an answer, the remote system must be available right now, and a timeout is a real possibility. A vague statement such as "Salesforce talks to billing" tells them none of that.
The problem patterns solve
Without patterns, each integration is designed from scratch, usually under deadline. Several things tend to go wrong.
- Wrong timing model. A developer calls an external system from a trigger and makes the user wait, when the business only needed the data to arrive within a few minutes.
- Hidden coupling. Salesforce can only save an order if the ERP answers immediately. When the ERP is down for maintenance, sales stops.
- Silent data loss. A message is sent once, the network drops it, and nobody notices because nothing checks for failure.
- Duplicates. A retry creates a second invoice because the receiver cannot tell a repeat from a new request.
- Limit surprises. A design that works for 10 records fails at 10,000 because it uses one callout per record.
Each of these is a design problem, not a coding problem. Better Apex does not fix a design that waits for a slow system the business never needed to wait for. Choosing a pattern first removes most of them before any code is written.
Four questions that define a pattern
Every integration can be described by four questions. The answers separate the three patterns.
- Timing. Does the sender need the result now, or can processing happen later?
- Coupling. How much does the sender depend on the receiver being available and fast?
- Failure behavior. If a step fails, who finds out, and who retries?
- Volume. Does one message carry one record, or does one job carry millions?
Keep these questions in mind. The later chapters on synchronous and asynchronous communication, limits, and choosing a pattern all return to them.
The three core patterns
This tutorial covers three patterns. They are introduced here briefly. Each gets its own chapter.
Request-reply
The caller sends a request and waits for a response before continuing. In Salesforce, the typical implementation is an Apex callout to an external service, or an external system calling the Salesforce REST API and reading the result.
Use it when the answer changes what happens next. Examples are checking a credit score before approving a quote, or showing live invoice status on a record page.
Its failure behavior is direct. The caller sees the error or the timeout immediately and can decide what to do. The cost is tight coupling: if the receiver is slow or down, the caller is slow or blocked.
Fire-and-forget
The sender publishes a message and moves on without waiting for the receiver to process it. In Salesforce this is usually a platform event, or Change Data Capture for changes to records. The sender gets confirmation that the platform accepted the message. It gets no confirmation that any subscriber acted on it.
Use it when other systems need to know something happened but the sender does not need an answer. An example is announcing that an order has shipped.
Coupling is loose. The sender and receivers do not need to be online at the same time. The cost is that failure moves downstream. If a subscriber fails, the publisher does not know, so you need replay, retries, and monitoring on the subscriber side.
Batch sync
A job moves a large set of records, usually on a schedule or on demand, and runs without a user waiting. In Salesforce, Bulk API 2.0 is the main tool for this. An example is loading a nightly export of 2 million product prices from an ERP.
Use it when volume is high and a delay is acceptable. The cost is latency: data is only as fresh as the last run. Failures are partial, so a job can succeed for most rows and reject others. You then need to read the per-record results.
Side by side
| Question | Request-reply | Fire-and-forget | Batch sync |
|---|---|---|---|
| Timing | Immediate, caller waits | Sender continues, delivery follows | Delayed, job-based |
| Coupling | Tight | Loose | Loose |
| Typical volume | One record or a few | One event at a time, many events overall | Thousands to millions of records |
| Who sees a failure | Caller, right away | Subscriber, often later | Job owner, in job results |
| Typical Salesforce tool | Apex callout, REST API | Platform events, Change Data Capture | Bulk API 2.0 |
The table shows tendencies, not rules. A request-reply call can fail, be retried, and still be correct. A batch job can be triggered by an event. Real systems combine patterns, which is why the later chapters on choosing a pattern and on idempotency matter.
How the patterns look in time
The next diagram shows the difference in who waits. In request-reply, the caller is blocked until the reply arrives. In fire-and-forget, the publisher continues after the platform accepts the event. In batch sync, the caller submits a job and checks the results later.
A short worked example
Consider a company that sells equipment. Three requirements arrive in one week.
- When a rep prices a quote, the tax amount must come from an external tax engine. The rep sees the number on screen.
- When an order ships, the warehouse system, the customer portal, and the analytics platform all need to know.
- Every night, the ERP's 800,000 product records must be reflected in Salesforce.
Applying the four questions:
- Requirement 1 needs the result now and involves one quote. This is request-reply. The rep waits a second or two, and the design must handle the tax engine being slow.
- Requirement 2 has several receivers and the sender does not need an answer. This is fire-and-forget. Publishing one event serves all three subscribers without Salesforce knowing who they are.
- Requirement 3 has high volume and tolerates delay. This is batch sync. A Bulk API 2.0 job is a better fit than 800,000 individual calls.
Using one pattern for everything would have been worse in each case. Fire-and-forget cannot return a tax amount to a waiting user. Request-reply to three systems from one trigger makes shipping fail when the portal is down. Record-by-record calls would exhaust API limits long before the nightly job finished.
Common errors this chapter helps you avoid
- Treating "integration" as one thing. The first design question is the timing model, not the tool. Picking Bulk API 2.0 or platform events before you know the timing model skips the decision that matters most.
- Assuming asynchronous means unreliable, or synchronous means safe. Both can be reliable if failure handling is designed. Synchronous calls fail visibly. Asynchronous ones can fail quietly unless you monitor them.
- Ignoring Salesforce's own constraints. Apex runs under governor limits, which are per-transaction caps on resources such as callouts and CPU time. For example, a transaction can make at most 100 callouts, and Apex cannot make a callout while uncommitted database changes are pending in the same transaction. These constraints push some designs toward asynchronous Apex or events. A later chapter covers them in detail.
- Skipping idempotency. An operation is idempotent when running it twice has the same effect as running it once. Any pattern that can retry needs this property, or retries create duplicates.
- Hard-coding endpoints and secrets. Callouts that embed hosts and credentials in code are hard to rotate and easy to leak. Named Credentials, covered in a later chapter, exist for this reason.
How the rest of the tutorial is organized
The chapters build in layers.
- The first chapters cover foundations: synchronous and asynchronous trade-offs, the Salesforce integration surfaces (REST API, Apex callouts, platform events, Change Data Capture, and Bulk API 2.0), and authentication with Named Credentials.
- Three chapters then implement the patterns: request-reply, fire-and-forget, and batch sync, each with working code.
- The final chapters cover the cross-cutting concerns that make integrations safe to run: limits, idempotency with external IDs, error handling and replay, choosing a pattern, and monitoring.
By the end you should be able to take a business requirement, decide which pattern fits, name the Salesforce feature that implements it, and explain what happens when it fails.
Summary of the key ideas
- A pattern describes timing, coupling, failure behavior, and volume, independent of any product.
- Request-reply waits and is tightly coupled. Fire-and-forget does not wait and is loosely coupled. Batch sync moves volume with delay.
- Most integration bugs come from a mismatch between the business need and the timing model, not from syntax errors.
- Patterns are combined in practice, so the goal is to choose deliberately for each requirement.
Exercise
A support agent opens a case and the page must display the customer's current account balance from an external billing system. Which pattern fits, and what is the main risk of that choice?
Show answer
Request-reply. The page needs the balance now, for one customer, so the call must wait for the answer. The main risk is tight coupling: if the billing system is slow or unavailable, the page is slow or shows an error. The design needs a timeout and a fallback message.
Exercise
Your company wants to tell four downstream systems whenever an opportunity closes as won. Salesforce does not need any result back from them. Which pattern fits, and where must failure handling live?
Show answer
Fire-and-forget, for example a platform event that each system subscribes to. Salesforce only learns that the platform accepted the event. Failure handling must live on the subscriber side, through replay, retries, and monitoring, because the publisher cannot see whether a subscriber processed the event.
Exercise
A teammate proposes loading 1.5 million records from a data warehouse each night by making one REST API call per record. Name two problems with this and the pattern you would use instead.
Show answer
One call per record uses a very large number of API requests, which risks hitting API limits, and it is slow because of per-call overhead. Both make the nightly window hard to meet. Use batch sync with a Bulk API 2.0 job, ideally an upsert on an external ID so reruns do not create duplicates.