Sub topic 14
Local and packaged distribution
This chapter covers the distribution state of an external client app (ECA) and what it changes. It assumes you know the ECA settings versus policies split from the previous chapter, and that you can navigate Setup and run sf CLI commands.
What distribution state means
Every ECA has a distribution state. The state records where the app is meant to run, and it decides which parts of the app can travel to other orgs.
- Local: the app belongs to one org. You create it there, configure it there, and use it there. Nothing about it is meant to be installed elsewhere.
- Packaged: the app is meant to ship inside a package, such as a second-generation managed or unlocked package, and be installed into other orgs. Typical cases are an ISV product or a team that promotes the same integration from a dev org through sandboxes to production.
A connected app had no such field. Any connected app could be put in a package, but its settings and its access rules were stored together. Installing one in another org often meant reviewing OAuth settings and admin policies that arrived mixed together. The ECA model avoids that by keeping the two sides apart and using the distribution state to decide how they are handled.
What travels and what stays
The ECA split is the key to packaging. Developer-owned settings describe what the app is: its OAuth scopes, callback URLs, and flows it supports. Admin-owned policies describe who may use it and how: permitted users, IP relaxation, session and refresh token behavior.
| Part | Owner | Local app | Packaged app |
|---|---|---|---|
| Settings (scopes, callback URLs, flows) | Developer | Edited in the org | Defined in the packaging org and delivered in the package |
| Policies (permitted users, IP rules, token lifetime) | Subscriber admin | Edited in the org | Set by the admin of each installing org |
| Consumer key | Generated by Salesforce | Used in the org | Identifies the app in installing orgs |
| Consumer secret | Generated by Salesforce | Viewed by authorized users in the org | Not shipped in the package. Retrieve it in each org that needs it |
Treat the last two rows as the behavior to verify in your own org. The reason is that Salesforce changes ECA details between releases. The principle holds either way: a package should never carry secrets, and the installing admin decides who can use the app.
How the pieces flow
The diagram shows the path of a packaged ECA from the org where it is built to the orgs that use it.
For a local app the path is shorter. Steps B through D disappear, and the same person or team often owns both the settings and the policies.
Choosing a state
Use these criteria.
- Does the app need to exist in more than one org? If it only serves your production org, choose Local. A sandbox that needs the same integration can often get it from a source-driven deployment instead of a package.
- Do different orgs need different access rules? If so, Packaged fits, because policies stay with each installing org's admin.
- Are you an ISV or shipping to customers? Choose Packaged. A customer's admin will want to review the scopes and then set their own policies.
- Is this a quick internal integration? Start Local. It has the least overhead, and you can package later if the need appears.
Check the current documentation before you plan to move an app between states. Changing a Local app to Packaged is the normal direction. Reversing a packaged app that has already been installed may be restricted, so don't count on it.
Working with the state in metadata
The distribution state is a field on the ExternalClientApplication metadata type. A trimmed example looks like this.
<?xml version="1.0" encoding="UTF-8"?>
<ExternalClientApplication xmlns="http://soap.sforce.com/2006/04/metadata">
<label>Order Sync</label>
<distributionState>Local</distributionState>
<contactEmail>[email protected]</contactEmail>
</ExternalClientApplication>The OAuth settings and policies live in separate metadata files. That separation lets a package include the settings file without the policies file. The next chapter covers these files and source-driven deployment in detail.
Common errors and gotchas
- Treating a package install as a finished setup. After installation the app typically has no usable access rules for your users until the admin configures policies. A user who sees an authorization failure after install is often hitting this gap, not a scope problem.
- Editing settings in a subscriber org. Developer settings in an installed packaged app are owned by the package. Changing the callback URL means releasing a new package version, not editing the installed copy.
- Assuming the secret came with the package. It did not. Each org needs its own credential handling, and a pipeline that hard-codes one secret for all orgs will fail in the others.
- Packaging too early. A packaged app adds versioning work. If the app has one consumer, Local avoids that work.
- Mixing up the state with the flow. Distribution state says nothing about whether you use authorization code, JWT bearer, or client credentials. You choose the flow separately in the OAuth settings.
Checking an installed app
After install and policy setup, confirm the app works by requesting a token with the flow you configured, and then calling the API. The last step from the earlier chapters applies unchanged.
curl https://MyDomain.my.salesforce.com/services/data/ \
-H "Authorization: Bearer $ACCESS_TOKEN"If this returns the list of API versions, the token is valid and the subscriber's policies allow the user. If it fails, check the policies first and the package second.
Exercise
Your company sells an integration to many customers. Each customer wants to decide which of its own users may authorize the app, and none of them should receive your consumer secret in the package. Which distribution state fits, and which part of the ECA does each customer's admin control?
Show answer
Packaged. The package carries the developer settings (scopes, callback URLs, supported flows). Each customer's admin sets the policies in their own org, such as permitted users, IP relaxation, and refresh token behavior. The consumer secret is not delivered in the package, so each org obtains its own.
Exercise
A teammate installed a packaged ECA in production, but users get an authorization error even though the scopes match what the app requests. What should you check first, and why?
Show answer
Check the policies in the production org, especially the permitted users setting and the profiles or permission sets assigned to the app. Policies are not delivered by the package, so a fresh install has no admin-approved access until an admin sets them.