Sub topic 15
A Decision Framework with Worked Scenarios
This chapter turns the earlier material into a repeatable procedure. It assumes you know the native Salesforce options (Flow, Apex callouts, Named Credentials, Platform Events, APIs), the limits that shape them, and what a middleware layer such as MuleSoft adds. The goal is to pick an approach for a concrete integration and defend the choice in a design review.
Why a framework helps
Teams usually decide by habit. Salesforce developers reach for Apex, and organizations that own MuleSoft route everything through it. Both habits produce bad outcomes. A framework forces you to state the facts of the integration first and choose the tool second.
The framework has three steps:
- Describe the integration in six dimensions.
- Check for hard triggers that decide the question on their own.
- Weigh the remaining signals, including cost and ownership, and record the decision.
Step 1: Six questions
Answer each question about the specific integration, not about your architecture in general.
| Dimension | Signals that native is enough | Signals that middleware is justified |
|---|---|---|
| Topology | Salesforce talks to one or two systems | Three or more systems, or several consumers of the same data |
| Transformation | Field-to-field mapping, simple JSON | Many formats (XML, CSV, EDI), joins across sources, shared canonical models |
| Reliability | Occasional failure is tolerable, a user can retry | Guaranteed delivery, replay, dead-letter handling, ordered processing |
| Volume and limits | Well inside API and governor limits | Bursts or sustained volume close to limits, or heavy fan-out |
| Security and governance | One Named Credential, standard OAuth | Central policy enforcement, API catalog, audit and monitoring across many integrations |
| Ownership and cost | No integration team, small scope | A platform team exists, and reuse across projects pays back the license |
Step 2: Hard triggers
Some facts settle the question regardless of the other answers.
- A protocol or security scheme Salesforce cannot speak. Examples are message queues, SFTP-only partners, or SOAP services with message-level security. Native tools are built around HTTP callouts, so a mediator is needed.
- Orchestration with compensation. If step four fails, steps one to three must be undone. Writing this in Apex or Flow is possible but fragile.
- Salesforce would be the hub by accident. If Salesforce is the only place that knows how to reach every other system, the integration logic should move out of it.
Hard triggers in the other direction exist too. If the whole integration is one request-reply call from a record page, middleware adds a network hop, a deployment pipeline, and a license for no gain.
Step 3: Weigh and record
For everything else, count signals. The script below encodes the weights used in this chapter. It is a thinking aid, not an oracle. Adjust the weights to your organization and keep the discussion it prompts.
MIDDLEWARE_SIGNALS = {
"more_than_two_systems": 2,
"heavy_transformation": 2,
"needs_orchestration": 3,
"non_http_protocol": 3,
"guaranteed_delivery": 2,
"volume_near_limits": 2,
"central_governance": 1,
"existing_platform_team": 1,
}
def recommend(answers):
"""Return (score, recommendation) for a dict of signal -> bool."""
score = sum(w for name, w in MIDDLEWARE_SIGNALS.items() if answers.get(name))
if score <= 2:
return score, "native Salesforce tools"
if score <= 5:
return score, "borderline: prototype native, review ownership and cost"
return score, "middleware"
if __name__ == "__main__":
order_lookup = {}
order_lifecycle = {
"more_than_two_systems": True,
"needs_orchestration": True,
"non_http_protocol": True,
"guaranteed_delivery": True,
}
print(recommend(order_lookup))
print(recommend(order_lifecycle))Running it prints (0, 'native Salesforce tools') and (10, 'middleware').
The flow below shows the same logic as a decision path.
Worked scenarios
Scenario A: Order status on a case page
Support agents need the current shipping status of an order, held in an ERP that exposes a REST endpoint. The call happens when an agent opens the case.
- Topology: two systems.
- Transformation: one field read.
- Reliability: if the call fails, the agent clicks refresh.
- Volume: a few thousand calls a day.
The score is 0. A native callout through a Named Credential is enough, and it keeps secrets out of code:
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'));
}Edge case: this stays native only while the ERP responds quickly. Callouts have a maximum timeout of 120 seconds, and a slow ERP blocks the user's page. If the ERP is routinely slow, the answer is caching or an asynchronous design, not automatically middleware.
Scenario B: Order lifecycle across six systems
A quote becomes an order in Salesforce. The order must reserve stock in a warehouse system, create an invoice in billing, notify a carrier over a legacy SOAP interface, and send a confirmation. If billing fails, the stock reservation must be released.
This scenario hits three hard triggers: orchestration with compensation, a protocol Salesforce does not handle well, and more than two systems. The score is 10. Middleware fits.
A sensible split keeps Salesforce light. It publishes a Platform Event and does not know who listens:
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());
}
}The middleware subscribes, runs the sequence, handles retries, and calls the systems. In API-led terms, a process API owns the order sequence and system APIs wrap each back end.
Scenario C: Nightly sync of two million records
A data warehouse needs a full copy of several objects each night. Volume is high, but the shape is simple: extract, load, no business logic.
Signals: volume near limits (2), no orchestration, no heavy transformation. The score is 2, which points native, but the volume makes the answer less clear-cut. Bulk API 2.0 with a scheduled extract job, or a dedicated data-loading tool, handles this well. MuleSoft is not required. If your organization already runs it and wants one place to monitor all jobs, that is an ownership argument, not a technical need. Say so in the record.
Scenario D: Customer master data from two systems
Salesforce and an ERP both hold customers. A third system, a billing platform, holds a different ID scheme. Fields differ, duplicates exist, and three teams want to read the merged data.
Signals: more than two systems (2), heavy transformation (2), central governance (1). The score is 5, which is borderline. A mapping like this is what middleware centralizes:
%dw 2.0
output application/json
---
payload map (customer) -> {
Name: customer.company_name,
BillingCity: customer.address.city,
External_Id__c: customer.id
}The deciding question is reuse. If three teams need the same mapping, one maintained transformation beats three copies in Apex and Flow. If only Salesforce consumes it, a prototype in native tools may be enough.
Hybrid outcomes are normal
The result is rarely all or nothing. Scenario B uses native Platform Events at the Salesforce edge and middleware behind them. A realistic estate keeps simple lookups native and routes multi-system flows through middleware. Judge each integration on its own facts. Do not set a company-wide rule such as "all integrations go through the platform".
Writing the decision record
A defensible decision names the facts, the trigger or score, and the costs accepted. A short record has five parts:
- Context: systems involved, direction, volume, latency expectation.
- Signals found: which hard triggers and weighted signals applied.
- Decision: native, middleware, or hybrid, with the split described.
- Costs accepted: license, skills, operational ownership, on-call burden.
- Revisit conditions: for example, "reconsider when a third consumer appears or when daily volume doubles".
The revisit conditions matter most. Integrations that start native often outgrow it, and a stated threshold turns that into a planned migration instead of a surprise.
Common errors when applying the framework
- Scoring the architecture, not the integration. One platform team's enthusiasm should not raise the score of a trivial lookup.
- Ignoring ownership. A middleware flow nobody is trained to support is worse than a plain Apex class the team understands.
- Treating the score as a vote. One hard trigger outweighs many soft signals.
- Skipping the prototype on borderline cases. A short spike in native tools often shows whether limits or error handling are real problems.
- Forgetting failure paths. For every scenario, ask what happens when the far system is down for an hour.
Exercise
A sales team wants Salesforce to push closed-won opportunities to one internal REST service. The service is fast, and a missed push can be re-sent by an admin the next morning. Only two systems are involved. Using the chapter's weights, what is the score and the recommendation, and what single new fact would make you reconsider?
Show answer
No signals apply, so the score is 0 and the recommendation is native tools, such as a Flow or Apex callout using a Named Credential. A new fact that would change this is a guaranteed-delivery requirement (+2), or a requirement for the same event to feed two more systems (more than two systems, +2). Either one alone still scores 2 to 4, so you would prototype and review. Adding orchestration with compensation (+3) would move it toward middleware.
Exercise
Scenario C scored 2, yet some teams still choose MuleSoft for it. Give one valid reason and one invalid reason, and say where each belongs in the decision record.
Show answer
A valid reason is ownership: the organization already runs MuleSoft with monitoring and alerting for all jobs, so one more job adds little cost and keeps operations consistent. It goes under "Costs accepted" or "Context". An invalid reason is "it avoids Salesforce API limits". The middleware still calls Salesforce APIs, so the limits apply. It should be rejected during review, not recorded as a justification.