Sub topic 9
Deploying the agent to the target org
This chapter assumes you have already retrieved the agent metadata, built a package.xml manifest, and prepared the target org. You should also know basic Salesforce CLI usage and the layout of a Salesforce DX project. Here you validate the deployment, run it, and read the result.
How the deployment works
A deployment sends the components in your manifest to the target org as one unit. Salesforce checks that every component can be saved and that all dependencies resolve. If any required component fails, the whole deployment is rolled back. This is why the manifest must include the Apex classes, Flows, and permission sets that the agent's actions rely on.
Deploy in two steps. First run a validation-only deployment, which checks everything and saves nothing. Then run the real deployment.
Step 1: Validate with a dry run
The --dry-run flag runs the full deployment checks without changing the target org.
sf project deploy start \
--manifest manifest/package.xml \
--target-org target-org \
--dry-runRead the output before you continue. A failed dry run lists each failing component with a message. Typical causes are a missing dependency, a feature that is not enabled in the target org, or an Apex class that does not compile there.
Step 2: Deploy for real
When the dry run passes, run the same command without the flag.
sf project deploy start \
--manifest manifest/package.xml \
--target-org target-orgUse the same manifest for both steps. If you change the manifest between them, the validation result no longer describes what you deploy.
What you have after deployment
The metadata is now in the target org, but the agent is not ready to use. Three things are still open:
- The agent is not active. Activation is a separate step, covered in a later chapter.
- The agent user and permission sets may still need assignment.
- Environment-specific values, such as endpoints or record IDs, may still point at the source org.
Treat a successful deployment as "the components exist", not "the agent works".
Checking the deployment result
If you need to look at a deployment after the fact, query its status with the CLI.
sf project deploy report --target-org target-orgIn the Salesforce Setup UI, the Deployment Status page shows the same information, including per-component errors. Check it when the terminal output is too long to read.
Common problems at this stage
| Symptom | Likely cause | Fix |
|---|---|---|
| A component reports a missing reference | A dependency is not in the manifest | Add the Apex class, Flow, or permission set and validate again |
| A GenAiPlugin or GenAiFunction fails to save | The target org lacks the needed feature | Enable the feature in Setup and retry |
| A Flow action fails | The Flow is inactive or a different version exists | Deploy the active Flow version |
| An Apex class fails | A test or compile error in the target org | Fix the error and rerun the dry run |
Fix the first error in the list before the others. Later errors are often side effects of the first one.
Keeping the manifest narrow
Wildcards such as <members>*</members> are convenient while learning. For real projects, list the specific members the agent needs. A wildcard can pull in unrelated components from your project and make a deployment fail for reasons that have nothing to do with the agent.
Exercise
Why should you run a deployment with --dry-run before the real deployment, and what is still missing after the real deployment succeeds?
Show answer
A dry run checks that all components and dependencies deploy without saving anything, so you find errors before the target org changes. After a successful deployment the agent is still inactive, and you still need to assign the agent user and permissions and adjust environment-specific settings.