Example - Configure String Replacement for Agent Username

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:

  • Specify the string to replace as digitalagent.00dob000002dgxhf324f6b53d31@salesforce.com.
  • Specify that the environment variable TARGET_AGENT_USER will hold the new username.
  • Pass the new username on the command line, rather than setting the environment variable.

Step 1 - Find Your Source Org's 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:

Default Username
1default_agent_user: "digitalagent.00dob000002dgxhf324f6b53d31@salesforce.com"

Step 2 - Update Your sfdx-project.json File 

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).

Configure sfdx-project.json to Update Agent Username During Deployment to the Target Org
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}

Step 3 - Specify Source Username During Deployment 

When executing the deployment, assign the target org’s agent username to the TARGET_AGENT_USER environment variable.

Specify String Substitution and Deploy Agent Metadata to the Target Org
1TARGET_AGENT_USER="digitalagent.00dob000002dgw5b9802e014bf4@salesforce.com" sf project deploy start --source-dir force-app --target-org my-target