Set Up Your DX Environment
Manage Data Libraries
Manage MCP Servers
Preview and Debug an Agent
Manage an Agent
Example: Configure String Replacement for Agent Username
Troubleshoot Issues
Reference
This example shows you one way to use string replacement to update the agent’s username during deployment. This method works with committed and uncommitted agents.
In this example, we:
digitalagent.00dob000002dgxhf324f6b53d31@salesforce.com.TARGET_AGENT_USER will hold the new username.In the source org, find the username for the agent’s default user. The username is defined in an agent’s .agent file, in the default_agent_user property. For example:
1default_agent_user: "digitalagent.00dob000002dgxhf324f6b53d31@salesforce.com"In your Salesforce DX project’s sfdx-project.json file, configure your replacements property. Be sure to replace all instances of the agent username. In this example, we specify replacement in all metadata (*-meta.xml) and agent script (*.agent) files. We use the environment variable TARGET_AGENT_USER for string substitution. (Your project’s needs might be different).
1{
2 "packageDirectories": [
3 {
4 "path": "force-app",
5 "default": true
6 }
7 ],
8 "name": "test_metadata_string",
9 "namespace": "",
10 "sfdcLoginUrl": "https://login.salesforce.com",
11 "sourceApiVersion": "66.0",
12 "replacements": [
13 {
14 "glob": "force-app/main/default/bots/**/*-meta.xml",
15 "stringToReplace": "digitalagent.00dob000002dgxhf324f6b53d31@salesforce.com",
16 "replaceWithEnv": "TARGET_AGENT_USER"
17 },
18 {
19 "glob": "force-app/main/default/aiAuthoringBundles/**/*.agent",
20 "stringToReplace": "digitalagent.00dob000002dgxhf324f6b53d31@salesforce.com",
21 "replaceWithEnv": "TARGET_AGENT_USER"
22 }
23 ]
24}When executing the deployment, assign the target org’s agent username to the TARGET_AGENT_USER environment variable.
1TARGET_AGENT_USER="digitalagent.00dob000002dgw5b9802e014bf4@salesforce.com" sf project deploy start --source-dir force-app --target-org my-target