Sub topic 10
Security, governance, and monitoring of integrations
This chapter assumes you know basic Salesforce concepts (objects, records, the APIs), how REST and JSON work, and what an integration between two systems is. It covers what you must secure, govern, and watch in an integration. It also shows which of those jobs Salesforce does natively and which a middleware layer adds.
Why this concern decides architecture
An integration moves business data across a trust boundary. Each connection adds credentials to store, endpoints to expose, and failures to notice. Security, governance, and monitoring are the three jobs that keep this manageable:
- Security controls who or what can call an interface, and what data they can see.
- Governance sets the rules for how interfaces are designed, versioned, shared, and retired.
- Monitoring shows whether integrations are working, how fast they are, and why they failed.
With two or three connections, native tools cover these jobs well. With dozens, the lack of one central place for policy and visibility becomes the main cost. This is why the topic belongs in the middleware decision.
Security for native Salesforce integrations
Authentication
Salesforce supports several ways to authenticate. Pick the one that matches who is calling.
| Scenario | Common choice | Notes |
|---|---|---|
| External system calls Salesforce, no user present | OAuth 2.0 client credentials or JWT bearer flow with a Connected App or External Client App | Run as a dedicated integration user with minimal permissions |
| External system calls Salesforce on behalf of a user | OAuth 2.0 web server flow | Access is limited by that user's permissions |
| Salesforce calls an external system | Named Credential with an External Credential | Credentials stay out of code |
| Browser or mobile client | OAuth 2.0 with PKCE | Do not embed secrets in client code |
Avoid username-and-password flows and shared admin accounts. If an integration user is compromised, the damage should be limited to what that user can do.
Keeping secrets out of code
The Apex callout below uses a Named Credential. The endpoint begins with callout:, and Salesforce injects the authentication at runtime.
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'));
}No password, token, or URL appears in the code. An admin can rotate the secret or change the endpoint without a deployment. Hard-coded endpoints and keys in Apex, custom settings, or Flow text values are the most common native security mistake.
Least privilege inside Salesforce
Authentication proves identity. Authorization decides what that identity can do. For an integration user:
- Create a dedicated user, not a person's account.
- Grant access through permission sets, with only the objects and fields the integration needs.
- Remember that API access does not bypass sharing unless you give it "View All" or "Modify All" rights. Avoid those.
- In Apex, decide deliberately between
with sharing,without sharing, and field-level checks such asWITH USER_MODEin SOQL.
Protecting data in transit and at rest
All Salesforce API traffic uses TLS. For callouts, require HTTPS endpoints. If your data is sensitive, consider Shield Platform Encryption for stored fields. Be aware that encrypted fields have restrictions in filtering and searching, and these affect integration queries.
Where native security runs out
Native tools secure each connection one at a time. Gaps appear as the number of connections grows:
- Scattered credentials. Each Named Credential, Connected App, and external system holds its own secrets. Rotation is a manual job per connection.
- Per-integration policy. Rate limiting, IP allow-listing, and payload validation are not applied uniformly. You build each one yourself, or you skip it.
- No shared threat protection. Native callouts do not give you a gateway that checks for oversized payloads, malformed JSON, or injection attempts before traffic reaches a back-end system.
- Direct exposure of back ends. In a point-to-point design, a legacy system may need to accept calls straight from Salesforce, which means opening network paths to it.
What middleware adds
A middleware layer, such as MuleSoft Anypoint Platform, places a managed gateway and policy engine between systems. Typical security and governance capabilities:
- API gateway policies. Apply client ID enforcement, OAuth token validation, rate limiting, IP allow-lists, and JSON threat protection to an API through configuration, not code. The same policy can be applied to many APIs.
- Central credential handling. Secrets for back-end systems live in the middleware, not in Salesforce. Salesforce holds one credential, for the middleware.
- Protocol and identity mediation. A legacy system that only supports SOAP with basic authentication can sit behind an API that offers OAuth to callers.
- Network placement. Runtime workers can run inside a private network or VPC, so on-premises systems are reached without exposing them to the internet.
- Governance tooling. An API catalog (Anypoint Exchange in MuleSoft) lists available APIs, their specifications, and their versions. Teams reuse an existing API instead of building another point-to-point link.
- Audit support. Policy changes, deployments, and API access can be recorded and reviewed.
The diagram shows where the policy enforcement point sits.
Middleware does not make security automatic. A misconfigured policy, an over-permissioned API client, or an unprotected management console is still a risk. You also now secure one more system.
Governance in practice
Governance is mostly about decisions made once and applied many times.
- Standards. Naming, error formats, authentication methods, and versioning rules for every API.
- Contracts first. Write the API specification (for example in OpenAPI) before building, so consumers and providers agree on the shape of the data.
- Versioning and deprecation. Change an API without breaking consumers. Salesforce itself retires old API versions, so integrations that call fixed versions need a review schedule.
- Ownership. Each interface has a named owner who answers when it breaks.
- Reuse over rebuild. Search the catalog before creating a new interface.
Natively, governance relies on documentation, naming conventions, and review discipline. This works for a small team and weakens as teams multiply.
Monitoring and observability
Monitoring answers three questions: is it up, is it fast, and what went wrong.
Native visibility
- Event Monitoring and Setup Audit Trail show API usage, logins, and configuration changes.
- API usage in Setup shows consumption against daily API limits.
- Debug logs and Apex exceptions capture callout errors, but they are short-lived and not built for long-term analysis.
- Platform Event publishing returns a result you must check, as shown below.
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());
}
}Writing errors only to System.debug is not monitoring. In production, record failures in a custom object or log platform and raise an alert.
Middleware visibility
A middleware layer sees traffic from many systems and can report on all of it in one place:
- Dashboards for request volume, response time, and error rate per API.
- Transaction tracing with a correlation ID that follows one business transaction through Salesforce, the gateway, and each back end.
- Alerts on error thresholds, latency, or failed message queues.
- Replay and dead-letter handling for failed messages, so operators can retry without asking a developer.
A correlation ID is the key practice here. Generate it at the first system, pass it in a header, and log it everywhere. Then one search finds the entire path of one order.
Decision signals
| Signal | Leans native | Leans middleware |
|---|---|---|
| Number of connected systems | One or two | Many, or growing |
| Back-end exposure | Modern HTTPS APIs | Legacy or on-premises systems needing network isolation |
| Policy needs | Basic authentication, no rate control | Uniform rate limits, threat protection, audit rules |
| Compliance | Standard Salesforce controls suffice | Needs central audit, tracing, and data-flow evidence |
| Monitoring | Salesforce logs and a custom error log are enough | Operations team needs cross-system dashboards and alerts |
| Team | Salesforce admins and developers only | Dedicated integration team with API governance |
Treat these as signals, not a score. One strong signal, such as a regulatory audit requirement across systems, can outweigh several weak ones.
Common mistakes
- Using a personal or admin account for the integration user.
- Storing keys in Apex, custom labels, or Flow text variables instead of Named Credentials.
- Giving the integration user "Modify All Data" because it is easier than finding the exact permissions.
- Logging full payloads that contain personal data into debug logs or a log platform.
- Adding middleware but leaving the back-end systems reachable directly, so the gateway policies can be bypassed.
- Having no alert on failures, so a broken integration is found by a business user days later.
Exercise
A company has Salesforce calling an on-premises ERP, a billing system, and a shipping service. Each link uses a separate hard-coded key in Apex, and nobody can say which calls failed last week. Name two security or governance problems and one monitoring problem, and say which problems middleware would solve and which require changes you can make natively.
Show answer
Security: hard-coded keys in Apex and no central policy such as rate limiting. Governance: no single owner or catalog of the three interfaces. Monitoring: failed calls are not recorded anywhere visible. Moving keys into Named Credentials and logging errors to a custom object are native fixes. Middleware would add central policy enforcement, a catalog, network isolation for the on-premises ERP, and cross-system dashboards with alerts. With only three interfaces, the native fixes may be enough, and middleware becomes more attractive as interfaces multiply or the ERP must stay off the public internet.
Exercise
Why is a correlation ID useful, and where should it be created?
Show answer
It is a unique identifier attached to one business transaction and passed in a header through every system, so one search in the logs shows the whole path. Create it at the first system that starts the transaction, and reuse it, rather than generating a new one, at each later hop.