Sub topic 12
Fixing common deployment errors
This chapter assumes you can run sf project deploy start against a Salesforce DX project and read its output. It also assumes you know the agent metadata types (Bot, BotVersion, GenAiPlanner, GenAiPlugin, GenAiFunction) and the dependencies they reference: Apex classes, Flows, and permission sets. Here you learn to sort a failed agent deployment into a few categories and fix each one.
Read the failure before changing anything
A failed deployment reports one error per component, and one root cause often produces several errors. A missing Apex class, for example, can make a GenAiFunction fail, then the GenAiPlugin that references it, then the GenAiPlanner above that. Fix the lowest component in the chain first, then deploy again.
Always get the full detail. The default table output can truncate long messages.
sf project deploy start \
--manifest manifest/package.xml \
--target-org target-org \
--dry-run \
--verbose \
--json > deploy-result.jsonIf the command stops waiting or your terminal drops, the deployment may still be running in the org. Use the job ID to read its status:
sf project deploy report --use-most-recent --target-org target-orgRun the validation-only deployment (--dry-run) repeatedly while you fix errors. It checks everything the real deployment checks but saves nothing in the target org.
A triage model
Most failures fall into five categories. Work through them in this order, because earlier categories cause later ones.
Category 1: The target org does not support the feature
Symptoms: the deployment reports that a metadata type is unknown or not available, or it rejects Bot or GenAiPlanner components outright.
Causes:
- Agentforce, Einstein generative AI, or the related setup is not enabled in the target org.
- The target org is on an older release than the source org, so it does not know a type or field that the source org's API version introduced.
- The target org is a sandbox or scratch org created without the needed features.
Fixes:
- In the target org, confirm that the Agentforce and Einstein generative AI features are turned on in Setup. If your agent uses Data Cloud or other add-ons, confirm those too.
- Compare the
<version>inpackage.xmlandsourceApiVersioninsfdx-project.jsonwith what the target org supports. Lower the version only if no component you deploy needs the newer one. - For scratch orgs, add the required features and settings to the scratch org definition file and create a new org.
Category 2: Components not found
Symptoms: messages that say a component of some type "named X" cannot be found, or that a field value refers to something that does not exist. The exact wording varies by type.
Causes:
- A GenAiFunction points to an Apex class or Flow that is not in the manifest and does not exist in the target org.
- An Apex class refers to a custom object or field that was not deployed.
- The manifest uses specific member names, and one name has a typo or different casing.
- The component exists in the source org but was never retrieved into your project, so the manifest names something your local files do not have.
Fixes:
- Retrieve the missing component from the source org, then add it to the manifest.
- Deploy objects and fields before the code that uses them. If the dependency chain is long, make the first deployment contain only the foundation (objects, fields) and a second deployment contain code, Flows, and the agent.
- Check for inactive Flows. A Flow that is a required action target must have an active version in the target org. A Flow deployed as a draft cannot be used.
You can confirm what exists in the target org with a query. This checks whether the agent and its versions are already there:
sf data query \
--query "SELECT DeveloperName, MasterLabel FROM BotDefinition" \
--target-org target-org
sf data query \
--query "SELECT DeveloperName, Status FROM BotVersion" \
--target-org target-orgCategory 3: The agent user does not exist
Symptoms: the deployment of the Bot fails with an error about a user, or the Bot deploys but the agent cannot be activated.
Cause: an agent definition refers to its running user by username. Usernames are unique across all Salesforce orgs, and sandbox usernames carry a suffix (for example, .mysandbox). A username that works in the source org will not exist in the target org.
Fixes:
- Create the agent user in the target org, with the license and profile your agent type requires.
- Update the username value in the Bot metadata file to the target org's user. Do not edit this by hand for each deployment. Chapter content on environment-specific settings covers how to keep this value per environment.
- Verify the user is active:
sf data query \
--query "SELECT Username, IsActive FROM User WHERE Username = '[email protected]'" \
--target-org target-orgReplace the username with your own. An empty result means the user does not exist. IsActive of false means the user is frozen or deactivated.
Category 4: Permissions and access
Symptoms: the deployment succeeds, but actions fail at run time, the agent says it cannot do something, or the agent user cannot see records.
Causes:
- The permission set that grants access to Apex classes, Flows, and objects was not deployed, or was deployed but not assigned.
- The permission set was assigned to you but not to the agent user.
- A permission set lists a field or object that does not exist in the target org, so the permission set deployment fails and drags later steps with it.
Fixes: deploy the permission set before the agent, assign it to the agent user, and then test from that user's point of view.
sf org assign permset \
--name Agent_Action_Access \
--on-behalf-of [email protected] \
--target-org target-orgThe --on-behalf-of flag assigns the permission set to a user other than the one you logged in as. The permission set name and username above are placeholders.
Category 5: Active version conflicts
Symptoms: a message that you cannot change or overwrite an active version, or the deployment of a BotVersion fails when the target already has an active agent of the same name.
Cause: Salesforce does not let a deployment modify a version that is active.
Fix: deactivate, deploy, and activate again. Plan this as a maintenance step because the agent is unavailable while it is inactive.
sf agent deactivate --api-name My_Service_Agent --target-org target-org
sf project deploy start \
--manifest manifest/package.xml \
--target-org target-org
sf agent activate --api-name My_Service_Agent --target-org target-orgA different approach is to deploy a new version number and activate it, which leaves the old version in place until the switch. Use whichever your team's release process allows.
Quick reference
| Symptom | Likely cause | First fix |
|---|---|---|
| Unknown metadata type | Feature disabled or older release | Enable features, check API version |
| Component "not found" | Missing Apex, Flow, object, or field in manifest | Retrieve and add it, deploy foundation first |
| User error on Bot | Username does not exist in target | Create user, update the reference |
| Action fails at run time | Permission set missing or unassigned | Deploy and assign the permission set |
| Cannot change active version | Active BotVersion in target | Deactivate, deploy, reactivate |
| Flow action fails | Flow deployed as inactive | Activate the Flow version |
Edge cases
- Wildcards hide gaps. A manifest with
*forApexClassdeploys every class in your local project, but it cannot add a class you never retrieved. A wildcard also deploys unrelated code, which can add unrelated failures. Narrow it to specific members once the agent works. - Test failures in production. When the target is a production org, Apex deployments need test coverage. A coverage error is not an agent problem. Run
--test-level RunLocalTestsand fix or add tests for the Apex that your actions use. - Partial progress. A deployment is all-or-nothing by default, so a failure leaves the target unchanged. Do not assume a partial deployment happened because the output lists many components.
- Stale local files. If the source org changed after your last retrieve, your local copy is out of date. Retrieve again before debugging.
Exercise
A deployment to a sandbox fails. The output lists errors for a GenAiFunction, a GenAiPlugin, and a GenAiPlanner. The GenAiFunction error says the Apex class it invokes cannot be found. What do you fix first, and why?
Show answer
Fix the missing Apex class first. The plugin and planner errors are most likely knock-on effects of the function failing, because they reference it. Retrieve the class from the source org, add it to the manifest, run the dry run again, and then check whether the other two errors disappear.
Exercise
The deployment succeeds and the agent activates, but every action that reads Account records fails for the agent user. Which category is this, and what do you check?
Show answer
This is a permission problem (Category 4). Check that the permission set granting object access and access to the Apex classes and Flows was deployed and assigned to the agent user, not only to the person who deployed. Confirm the user has the right license and profile, then test again as the agent user.
Exercise
Your validation-only deployment fails with "cannot change active version" for a BotVersion. Give the sequence of commands to resolve it and name one drawback.
Show answer
Run sf agent deactivate --api-name <name>, then sf project deploy start with your manifest, then sf agent activate --api-name <name>, all with --target-org. The drawback is that the agent is unavailable between deactivation and reactivation.