Sub topic 4
Preparing the target org
The previous chapter described how to inventory everything an agent depends on. This chapter covers the other half of that comparison: checking that the target org can accept those dependencies. The target is the org you deploy to, such as a UAT sandbox or production. Most failed agent deployments trace back to a target org that is missing a feature, a license, or a prerequisite component, not to a mistake in the manifest.
This chapter assumes you can use Salesforce CLI, know what permission sets and permission set licenses are, and have an inventory of the agent's Apex classes, Flows, objects, and permission sets from the previous chapter.
Why readiness matters
Metadata deployment checks that each component is valid in the target org. It does not turn on features for you. Deploying GenAiPlanner metadata to an org where Agentforce is not enabled fails, or succeeds without producing a usable agent. The same applies to a Flow that references a custom field the target org does not have.
Readiness checks fall into four groups:
- Feature enablement: the org-level switches that make agent metadata types available.
- Licensing: the licenses that the agent user and the agent's users need.
- Dependencies the agent calls: objects, fields, Apex, Flows, and data the actions rely on.
- Channel and integration setup: messaging, Omni-Channel, or other entry points the agent is attached to.
Feature enablement
Agent metadata types exist in an org only when the related features are on. In the target org, an administrator generally needs to confirm the following in Setup:
- Einstein generative AI is turned on (Einstein Setup).
- Agentforce is turned on (Agentforce Agents page).
- Any data or grounding feature that the agent uses, such as Data Cloud for retrieval from a data library, is provisioned and configured.
Menu names and required toggles change between releases, so check the current Salesforce Help page for your edition instead of relying on a remembered click path. Also note that enabling a feature in a sandbox does not enable it in production. Each org has its own settings, and most of them are not metadata that you deploy.
You can test whether the target org recognizes the agent metadata types before you build anything. Listing members of a type fails with an error if the type is unavailable:
sf org list metadata --metadata-type GenAiPlanner --target-org target-org
sf org list metadata --metadata-type Bot --target-org target-orgAn empty result means the type exists and no agents have been deployed yet. An error that names an unknown type points to a missing feature or an API version problem.
API version
The manifest in this tutorial uses version 63.0. The target org must support at least that API version, and the metadata you retrieved must be valid in it. Production orgs can lag sandboxes during a release window, because sandboxes preview a new release earlier. If the source is a preview sandbox and the target is production on the previous release, metadata written for the newer API version can fail on deploy. Check both orgs:
sf org display --target-org source-org
sf org display --target-org target-orgCompare the Api Version lines in the two outputs. Also confirm that sourceApiVersion in sfdx-project.json is not higher than the target supports.
Licensing
Three kinds of licenses matter for an agent.
- The agent user needs a user license and the permission sets that grant its access. An agent that runs as a dedicated service agent user usually uses a specific profile and permission set license. The next chapters cover the user setup itself. Here you only verify that a license is available.
- Human users who test or interact with the agent need access to the features it uses, such as the objects behind its actions.
- Some agent capabilities consume usage-based credits or require add-on licenses. Whether a given capability needs an add-on depends on your contract, so ask your account team if you are unsure.
You can list permission set licenses and how many are in use from the command line:
sf data query \
--query "SELECT DeveloperName, TotalLicenses, UsedLicenses FROM PermissionSetLicense ORDER BY DeveloperName" \
--target-org target-orgCompare TotalLicenses with UsedLicenses. A license with zero remaining seats blocks assigning the permission set that depends on it, and that failure shows up later, during user setup, which is harder to trace back.
User licenses can be checked the same way:
sf data query \
--query "SELECT Name, TotalLicenses, UsedLicenses FROM UserLicense WHERE TotalLicenses > 0" \
--target-org target-orgDependencies the actions call
The agent's actions run Apex and Flows, and those read and write objects. Your inventory from the earlier chapter should already list them. Preparing the target org means each item is either in the manifest or already in the target org.
Use this decision table for each dependency:
| Dependency | Where it should come from | Typical failure if missing |
|---|---|---|
| Custom object or field used by an Apex class or Flow | Include in the manifest, or deploy earlier in the pipeline | Compile error on the class or Flow |
| Standard object that needs a feature (for example, Cases or Work Orders) | Enable the feature in the target org | Component not found or object not supported |
| Apex class or Flow called by an action | Include in the manifest | The action references a missing target |
| Permission set that grants access to the Apex class or Flow | Include in the manifest | Agent action fails at run time with an access error |
| Reference data (knowledge articles, product records, picklist values) | Load as data, because metadata deployment does not move records | Agent answers from an empty set |
| Named credential or external service used by an action | Create or deploy per environment | Callout failure |
The distinction between metadata and data deserves emphasis. Agent topics and actions deploy as metadata. The records they read do not. If the agent in the sandbox answers questions from sandbox sample data, the target org needs equivalent real data, loaded separately.
Check for existing agents and name collisions
Before you deploy, find out whether the target org already contains an agent with the same API name. Deploying over an existing agent replaces its configuration, which may not be what you want.
sf data query \
--query "SELECT Id, DeveloperName, MasterLabel FROM BotDefinition" \
--target-org target-orgIf the query returns the agent's DeveloperName, decide whether this deployment is an update or a conflict. An active agent version cannot always be overwritten in place. The troubleshooting chapter covers the error cases.
Channels and integrations
An agent is reachable through a channel, such as an embedded chat deployment, Messaging for In-App and Web, or a Slack connection. Channel setup is often a mix of metadata and manual configuration. Two points apply to most setups:
- Routing objects such as Omni-Channel flows, queues, and service channels are metadata and can be included in the manifest. Verify that each one that the agent hands off to exists in the target org.
- Connected apps, domains, and external endpoints are tied to a specific org. A channel that works in a sandbox with a sandbox domain needs a new setup for the production domain.
Write down every channel the source agent uses and mark each item as "deployed" or "manual in target". That list becomes part of your release checklist.
A readiness checklist script
You can capture the checks above in a small script that runs before each deployment. It stops at the first failure, so a pipeline can call it as a gate.
#!/usr/bin/env bash
set -euo pipefail
TARGET="${1:?usage: preflight.sh <target-org-alias>}"
echo "Checking agent metadata types in $TARGET"
sf org list metadata --metadata-type GenAiPlanner --target-org "$TARGET" > /dev/null
sf org list metadata --metadata-type Bot --target-org "$TARGET" > /dev/null
echo "Org API version:"
sf org display --target-org "$TARGET" --json | grep -i '"apiVersion"'
echo "Permission set license usage:"
sf data query \
--query "SELECT DeveloperName, TotalLicenses, UsedLicenses FROM PermissionSetLicense WHERE TotalLicenses > 0" \
--target-org "$TARGET"
echo "Existing agents:"
sf data query \
--query "SELECT DeveloperName, MasterLabel FROM BotDefinition" \
--target-org "$TARGET"
echo "Validation-only deploy:"
sf project deploy start \
--manifest manifest/package.xml \
--target-org "$TARGET" \
--dry-runRun it as bash preflight.sh target-org. The last step reuses the validation deployment from the deploy chapter. Running it last means the cheap checks fail first.
Common mistakes
- Treating a successful validation as proof that the org is ready. A validation-only deployment checks metadata, not data, channel configuration, or licenses.
- Enabling features in the wrong org. Keep the org alias in every command explicit, and avoid relying on a default target org that may have changed.
- Assuming that a sandbox refresh copies the right setup. A full or partial sandbox copy brings metadata and some data from production, but newly enabled features may not carry over in the way you expect. Verify after every refresh.
- Leaving the license check until user setup. Check seat counts now so you are not blocked mid-release.
Summary of what to verify
Before moving to the retrieval and deployment steps, confirm that the target org has the agent features enabled, supports your API version, has free licenses for the agent user, contains or will receive each dependency from the inventory, has any needed data loaded, and has the channels configured. Record what you changed manually, because those steps repeat for every new target org.
Exercise
Your validation-only deployment to production passes, but after the real deployment the agent answers every question with "I don't have information about that." The agent worked in the sandbox. Name two readiness gaps that a metadata validation would not catch, and say how you would check each one.
Show answer
First, reference data may be missing. Agent topics and actions deploy as metadata, but the records they read (knowledge articles, product or case data) do not. Check by querying the relevant objects in the target org with sf data query and comparing counts with the source org. Second, a feature or setup needed for grounding may be off, for example a data library or Data Cloud setup, or a channel or permission configuration. Check the Setup pages for these features in the target org, and confirm that the agent user has a permission set granting access to the Apex classes, Flows, and objects the actions use. Validation checks only that the metadata is syntactically and referentially valid, not that data and org-level configuration exist.
Exercise
Write the sf command that lists the permission set licenses in an org that have seats, along with total and used counts.
Show answer
sf data query --query "SELECT DeveloperName, TotalLicenses, UsedLicenses FROM PermissionSetLicense WHERE TotalLicenses > 0" --target-org target-org