Sub topic 15
ECA metadata and source-driven deployment
This chapter assumes you know the ECA settings and policies split and the local and packaged distribution states from earlier chapters. You should also be comfortable with Salesforce DX projects and the sf CLI.
Why ECAs suit source control
A connected app stores its OAuth configuration in one metadata type, ConnectedApp, so settings and admin policies are mixed together. An external client app (ECA) splits that configuration across several metadata types. Developer-owned settings can travel through version control and a pipeline. Admin-owned policies stay under the control of the org that installs the app.
The metadata types
| Metadata type | Holds |
|---|---|
| `ExternalClientApplication` | Header: label, description, contact email, distribution state |
| `ExtlClntAppGlobalOauthSettings` | Org-independent OAuth settings such as the callback URL |
| `ExtlClntAppOauthSettings` | OAuth settings for this org, including scopes |
| `ExtlClntAppOauthPolicies` | Admin policies, such as permitted users and refresh token behavior |
The exact type names, folders, and file suffixes depend on your API version. Check the Metadata API reference for your version before you write a package.xml.
A minimal header file
The header file lives in the externalClientApps folder of your DX project.
<?xml version="1.0" encoding="UTF-8"?>
<ExternalClientApplication xmlns="http://soap.sforce.com/2006/04/metadata">
<label>Orders Integration</label>
<description>Server-to-server sync of orders</description>
<contactEmail>[email protected]</contactEmail>
<distributionState>Local</distributionState>
</ExternalClientApplication>Deploying with the CLI
Retrieve and deploy ECA metadata like any other type.
sf project retrieve start \
--metadata ExternalClientApplication \
--target-org dev-org
sf project deploy start \
--metadata ExternalClientApplication \
--target-org ci-orgTo deploy the OAuth settings too, add their types to the --metadata list or to your manifest.
Working practices
- Treat the header and OAuth settings as code. Review changes in pull requests.
- Deploy to a sandbox first, then promote the same files to production.
- Do not expect policies to arrive with the settings. After the first deployment to a new org, an admin still has to set permitted users, IP relaxation, and refresh token behavior.
- Use
Localfor apps owned by one org. UsePackagedonly when you are building a package for other orgs. - Re-retrieve after any change made in Setup, so source control does not drift from the org.
Exercise
A team deploys an ECA from source control to production. The deployment succeeds, but the integration cannot get an access token. Name two things to check, and say why the secret is not in the repository.
Show answer
Check that an admin has configured the ECA policies in production, such as permitted users and the run-as user or profile and permission set access. Also check that the consumer key and secret used by the integration come from the production org, not the sandbox. The secret is generated by the org and is sensitive, so it belongs in a secret store and not in version control.