Sub topic 12
Deploying the Action and Agent Configuration
This chapter covers moving an invocable Apex action and its agent configuration from a sandbox to another org. It assumes you can write and test an invocable class, you have registered it in Agent Builder, and you know the basics of Salesforce DX projects and the sf CLI.
What you are deploying
An Agentforce action built on Apex has two layers. Each layer is separate metadata, and both must reach the target org.
- Code: the Apex class and its test class (
ApexClass). - Agent configuration: the agent, its topics, and the actions assigned to those topics.
The agent configuration is stored as metadata types such as Bot, BotVersion, GenAiPlannerBundle, GenAiPlugin, and GenAiFunction. Their names and structure vary by API version. Check the Metadata API reference for your org's version before you write a manifest.
A custom action registered from Apex is a GenAiFunction. It points at your class by name. If the class is missing in the target org, the action cannot work.
Retrieve the metadata
Retrieve with a manifest so that the set of components is explicit and repeatable. This package.xml is an example. Adjust the member names and the API version for your org.
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>GetOpenCasesAction</members>
<members>GetOpenCasesActionTest</members>
<name>ApexClass</name>
</types>
<types>
<members>*</members>
<name>GenAiFunction</name>
</types>
<types>
<members>*</members>
<name>GenAiPlugin</name>
</types>
<version>64.0</version>
</Package>Add the agent types (Bot, BotVersion, GenAiPlannerBundle) when you also want to move the agent itself. Wildcards are convenient while learning. For production releases, list members by name so that unrelated work in the sandbox does not ship by accident.
Run the retrieve from your project folder:
sf project retrieve start --manifest manifest/package.xml --target-org MySandboxDeploy and run tests
Deploy to the target org and run the action's tests as part of the deployment:
sf project deploy start \
--manifest manifest/package.xml \
--target-org MyUat \
--test-level RunSpecifiedTests \
--tests GetOpenCasesActionTestProduction deployments require Apex tests to pass and meet the coverage rules. Keep the tests from the unit testing chapter in the same deployment as the class.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| Deployment fails on the action metadata | The Apex class is not in the package or failed to compile | Include the `ApexClass` in the same manifest |
| Action deploys but fails at runtime with an access error | The running user lacks class access or object permissions | Grant the permission set that includes the class and object access |
| Agent deploys but is inactive | Activation is a separate step in the target org | Activate the agent version in Agent Builder |
| Topic or action is missing from the agent | A metadata type was left out of the manifest | Add the missing type and redeploy |
| Agent works in the sandbox but not in the target | The target org lacks Agentforce or a required feature | Check the org's Agentforce setup |
Permissions travel separately
The action runs in user mode, so the running user's access still applies. Deploy the permission sets that grant the following, and assign them to the agent's running user:
- Access to the Apex class.
- Read access to
Case,Account, and the fields the query uses.
Verify after deployment
- Open the agent in the target org and confirm that the topic lists your action.
- Check that the action's instructions and input descriptions came across unchanged.
- Activate the agent version if it is not active.
- Use the agent preview with a record that has open cases and one that has none. Confirm both outputs.
- Test as a user with limited access, not only as an administrator.
Exercise
Your deployment of the agent to UAT succeeds, and the agent preview answers "No open cases were found" for an account you know has open cases. The same test works in your sandbox. What do you check first, and why?
Show answer
Check the running user's permissions in UAT. The action queries with WITH USER_MODE, so a missing class access, Case or Account object permission, or field permission makes the query return fewer rows or none. Deploy and assign the permission set that grants them, then retest as that user.