Sub topic 15
A decision framework with worked scenarios
This chapter assumes you know Salesforce objects and APIs, REST and JSON, and the basic native options: Flow, Apex callouts, Named Credentials, and Platform Events. It also assumes you have seen the signals for native versus middleware in earlier chapters. Here you combine them into one repeatable decision.
The framework in five questions
Ask these in order. Stop when an answer clearly decides the case.
- How many systems, and how many connections? One or two endpoints point toward native. Three or more systems, or a growing mesh of point-to-point links, point toward middleware.
- How complex is the data work? Field renaming and simple lookups fit Flow or Apex. Many source formats, canonical models, or protocol mediation (SOAP, files, EDI, queues) favor middleware.
- What reliability does the business need? Best-effort and user-visible retries are fine natively. Guaranteed delivery, replay, idempotency, and dead-letter handling favor middleware.
- Do Salesforce limits fit the volume? Check callout counts, API request allocations, and event volumes. If peak load strains them, move the work off-platform.
- Who will own it? Count the cost of licenses, skills, and on-call support. Middleware must be justified by the answers above, not by habit.
Worked scenario 1: order status lookup
A service agent needs the current order status from one ERP while viewing a case. The ERP exposes a REST endpoint.
- Systems: two. Data work: trivial. Reliability: if it fails, the agent retries. Volume: a few hundred calls a day.
- Decision: native. A Named Credential and an Apex callout are enough.
HttpRequest req = new HttpRequest();
req.setEndpoint('callout:ERP_Credential/orders/' + orderId);
req.setMethod('GET');
HttpResponse res = new Http().send(req);
if (res.getStatusCode() == 200) {
Map<String, Object> order = (Map<String, Object>) JSON.deserializeUntyped(res.getBody());
System.debug(order.get('status'));
}Adding middleware here adds a hop, a license, and a team to maintain it, with no benefit.
Worked scenario 2: customer master across five systems
Customer records live in an ERP, a billing system, an e-commerce platform, a legacy SOAP service, and Salesforce. Each uses different field names and IDs. New systems are planned.
- Systems: five and growing. Point-to-point would need up to ten connections.
- Data work: heavy. Each source needs mapping, such as the DataWeave transformation below.
- Decision: middleware. Build system APIs for each source and one process API for customer, so Salesforce talks to a single interface.
%dw 2.0
output application/json
---
payload map (customer) -> {
Name: customer.company_name,
BillingCity: customer.address.city,
External_Id__c: customer.id
}Worked scenario 3: shipment events
Salesforce must tell a warehouse system when an order ships, and a notification service may subscribe later.
- Salesforce publishes a Platform Event. It does not need to know who listens.
- If only one subscriber exists and loss is tolerable, native is enough. If the warehouse needs guaranteed processing, retries, and replay, put middleware as the subscriber and let it handle delivery.
Order_Event__e evt = new Order_Event__e(Order_Number__c = '10045', Status__c = 'Shipped');
Database.SaveResult result = EventBus.publish(evt);
if (!result.isSuccess()) {
for (Database.Error err : result.getErrors()) {
System.debug(err.getMessage());
}
}Defending the decision
Write the answer as a short record: the systems involved, the deciding question, the rejected option, and the condition that would change the decision. For scenario 1, that condition might be a second consumer of ERP data.
Common mistakes
- Choosing middleware because it is a company standard, without checking the questions above.
- Building a native point-to-point mesh and ignoring the fourth system.
- Ignoring operating cost: middleware needs monitoring, deployments, and skilled staff.
Exercise
A marketing tool needs a nightly export of new Salesforce Leads as JSON to one partner REST API. Volume is about 2,000 records. Delivery failures can be retried the next night. Which approach fits, and which question in the framework decides it?
Show answer
Native tools fit. Only two systems are involved, the transformation is simple, no guaranteed delivery or replay is needed, and 2,000 records a night is within limits. A scheduled Apex job or Flow with a Named Credential callout is enough. Questions 1 and 3 decide it. Revisit if more consumers or stricter delivery guarantees appear.
Exercise
A retailer must connect Salesforce, an ERP, a warehouse system that only accepts files, and a payments gateway, and must guarantee that no order is processed twice. Which approach fits, and why?
Show answer
Middleware fits. There are four systems, the warehouse needs protocol mediation (files), and "no duplicate processing" requires idempotency, retries, and dead-letter handling, which middleware provides as built-in features.