

# Troubleshoot real-time data integration

**Get help**  
For the stack, the guide and the gateway as the template creates them, open a case with AWS Support; see [Getting started with AWS Support](https://docs.aws.amazon.com/awssupport/latest/user/getting-started.html). Technical support depends on your support plan. For your Salesforce org, such as its users, sharing and automation, contact your Salesforce administrator or Salesforce support.

## What the setup script does and prints
<a name="real-time-data-integration-troubleshoot-script"></a>

The setup script in Step 2 does the following:

1. If the user doesn't exist and `profileName` is empty or names no profile, it lists your org's profiles, each with its user license and how many of that license are available, and stops.

1. It creates the user on that profile, without sending a welcome email. If a user with that username exists, it stops, unless the user already has the permission set and is active, or you set `reuseExistingUser` to `true`. It never changes your own user.

1. If `permissionSetLicense` names one, it assigns that permission set license to the user.

1. It creates or updates the permission set named in `psName`, replaces its object and field access, and assigns it to the user. If that permission set is already assigned to another user, it stops.

1. It reads back the user's object and system permissions, across every permission set the user holds, including the one that comes with its profile, and prints `PASS` or `FAIL` for each.

If any step fails, the script undoes every change it made in that run, prints `STOPPED: nothing was changed` with the reason, and stops. It's safe to run again: each run starts from what your org has.

Its values are at the top of the script, between `Your values` and `End of your values`:
+ `username`: a new username for the integration user, in the form of an email address. It must be unique across all Salesforce orgs, for example `connect-integration@example.org`, with your company's domain in place of `example.org`. The script stops while `username` or `email` still contains `yourcompany.com`.
+ `email`: an email address for the user, such as a team alias your Salesforce administrators read. Nothing in this guide's setup is sent to it or read from it, and the script sends no welcome email.
+ `lastName`: the name shown in **Created By** and **Last Modified By**.
+ `profileName`: the profile for a new user. Leave it empty the first time to list your org's profiles.
+ `permissionSetLicense`: optional. A permission set license to assign to the user, if your organization assigns one to the integration user.
+ `psName`: the permission set's API name. Keep `Connect_Real_Time_Data_Integration` unless your org already has a permission set with that name for another stack; the script stops if the permission set is assigned to any other user. A new name starts with a letter and has only letters, digits and single underscores, with none at the end, such as `Connect_Integration_Stack2`.
+ `reuseExistingUser`: keep `false`. Set it to `true` only to give this access to a user that already exists, for example an integration user your org already has. The script then makes that user an API-only user, and activates it if it is inactive.
+ `objects`: the objects and the access on each. To give access to your custom objects, add them, for example `'Order__c' => 'read,edit'`.
+ `runFlows`: `true` lets guides start autolaunched flows.
+ `apexClasses`: the invocable Apex classes guides call with `runApexAction`. The script adds access to these classes; it doesn't remove access to a class you take off the list.

The script ends with one of these lines:


**What the setup script prints**  

| Last line | What to do | 
| --- | --- | 
| `DONE: every permission passed`, after one `PASS` line for each object access and for **API Enabled**, **API Only User**, **Run Flows** and **Access Activities** | The user and its access are ready. Go on to create the External Client App. | 
| `STOPPED: nothing was changed. Set profileName to the profile you chose for the integration user`, after a list of profiles | Enter the profile you chose in `profileName`, exactly as listed, and run the script again. The list shows how many licenses are available for each profile. If the profile you chose has none available, ask your Salesforce administrator to choose another profile. | 
| `STOPPED: nothing was changed. The user's license can't grant every permission the integration user needs`, after a list of permission set licenses | See [Salesforce user and access](#real-time-data-integration-troubleshoot-user). | 
| `STOPPED: nothing was changed. Set username and email` | Change `username` and `email` at the top of the script, and run it again. | 
| `STOPPED: nothing was changed. … is your own user` | Enter a new username for the integration user, not your own. | 
| `STOPPED: nothing was changed. A user named … already exists` | Enter a new username. To give the access to that existing user instead, which makes it an API-only user, set `reuseExistingUser` to `true` and run the script again. | 
| `STOPPED: nothing was changed. Permission set … is assigned to other users` | Set `psName` to a new name, and run the script again. See [Salesforce user and access](#real-time-data-integration-troubleshoot-user). | 
| `STOPPED: nothing was changed. Set permissionSetLicense to one of these names` | The name doesn't match a permission set license. Enter one exactly as listed. | 
| `STOPPED: nothing was changed. The username … is already used in another Salesforce org` | Change `username`, for example by adding `.prod` or `.uat` at the end, and run the script again. | 
| `STOPPED: nothing was changed. Salesforce returned:` and a message | The message names the cause, such as an object in `objects` or a class in `apexClasses` that your org doesn't have. Fix that value and run the script again. | 
| `DONE WITH FAILURES`, after one or more `FAIL` lines | The user lacks the access marked `FAIL`. Give the user that access, and run the script again. | 
| No `LDI` lines; with the Salesforce CLI, `The script printed no LDI lines` and Salesforce's error | Paste the whole script again, from the first line to the last. In the Developer Console, check that **Debug Only** is selected, and read the error in the log. A compile error names the line it couldn't read, usually one you edited. | 

## Salesforce user and access
<a name="real-time-data-integration-troubleshoot-user"></a>

The setup script stops with `The user's license can't grant every permission the integration user needs`  
Salesforce refused a permission the script grants because of the integration user's license. The message names the permissions the user needs: **API Enabled**, **API Only User**, **Access Activities**, **Run Flows** when `runFlows` is `true`, and the object access in `objects`.  
The line before it, `Salesforce refused this access for the user's license`, has Salesforce's own message, such as `license doesn't allow the permission: RunFlow`. That message means the profile's user license doesn't include Run Flows, so Salesforce can't grant it to this user.  
Your Salesforce administrator decides which profile and any permission set license the user has. Then do one of the following, and run the script again:  
+ Set `profileName` to a profile that grants the access the user needs.
+ Set `permissionSetLicense` to a permission set license that grants it, as the script lists it.
+ If your guides don't run flows, set `runFlows` to `false`.

The setup script prints `the profile's user license has none available`  
Salesforce refused to create the user, because the profile's user license has none available. The script undoes the run and lists each profile with its available licenses. Your Salesforce administrator chooses another profile.

In Setup, assigning the permission set fails with `The user license doesn't allow the permission`  
Assign the user the permission set license your organization uses for that access, then assign the permission set again. For the steps, see [Assign a Permission Set License to a User](https://help.salesforce.com/s/articleView?id=platform.users_permissionset_licenses_assign&type=5) in Salesforce Help.

The setup script stops with `Permission set … is assigned to other users`  
The permission set named in `psName` already belongs to another integration, such as another stack's integration user, and the script would replace its permissions for every user who has it. Set `psName` to a new name that starts with a letter and has only letters, digits and single underscores, with none at the end, such as `Connect_Integration_Stack2`, and run the script again.

## External Client App and tokens
<a name="real-time-data-integration-troubleshoot-app"></a>

The token check in Step 2 requests a token from Salesforce, and with that token reads the username of the user the app runs as. The secret and the token stay in files that only you can read and that the block deletes when it ends; neither appears on screen or in the command's arguments.

The token check prints `OK` with another username  
The app's **Run As (Username)** names the wrong user. Correct it, and run the check again.

The token check prints `OK: …, but its username couldn't be read`, with a user ID  
The app issues tokens, but the token can't query the user. Check that the integration user has **API Enabled**, as the setup script's `PASS` lines show.

The token check prints `NO TOKEN: invalid_client_id`  
The consumer key is wrong, or the app is new and Salesforce hasn't finished setting it up. Run the check again later.

The token check prints `NO TOKEN: invalid_client`  
The consumer secret is wrong. Copy it again.

The token check prints `NO TOKEN:` with any other code  
Check that **Enable Client Credentials Flow** is selected and that **Run As (Username)** is the integration user.

The token check prints `isn't a My Domain URL`, `couldn't reach` or `didn't answer with JSON`  
Copy the My Domain URL again from Setup, **My Domain**, including `https://`.

**Create** does nothing when you create the External Client App  
The app's **API Name** is invalid, usually because a hyphen in the name carried into it. Use only letters, digits and single underscores in the API name.

The app's **Policies** tab has no **Run As** field  
Choose **Edit**, expand **OAuth Policies**, and under **OAuth Flows and External Client App Enhancements**, select **Enable Client Credentials Flow** again. **Run As (Username)** then appears; enter the integration user's username.

## Deploying and updating the stack
<a name="real-time-data-integration-troubleshoot-deploy"></a>

Deploying the stack fails at a flow or flow module, such as `GuideFlow`, with `InvalidContactFlowException: Invalid Action type. Type: InvokeExternalTool`  
The instance is on Connect Customer Basic, which has no External Tool block. In the AWS console, open the instance's **Connect Customer** page and, under **Enable Connect Customer across your entire instance**, choose **Enable**; or, if the page shows **Customer** and **Confirm Amazon Connect Customer**, choose **Change**. Then run the check in [Check the instance](real-time-data-integration-instance.md#real-time-data-integration-instance-check), which must print `Connect Customer plan (must be true): true`, delete the failed stack, and deploy again.

Retry a failed stack without deleting it  
You choose this before you create the stack, so it applies to your next attempt. On the **Quick create stack** page that Launch Stack opens, or on the **Configure stack options** page of the console's **Create stack** wizard, select **Preserve successfully provisioned resources** under **Stack failure options**. A create that fails then stops in `CREATE_FAILED` instead of rolling back, and keeps what it created. Fix the cause. If the fix is a different parameter value, choose **Update**, enter the new value, and keep **Preserve successfully provisioned resources** selected. Otherwise choose **Retry**. See [Choose how to handle failures when provisioning resources](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/stack-failure-options.html).

The stack is in `ROLLBACK_COMPLETE`, and launching again with the same name fails  
A stack whose first deployment failed stays in `ROLLBACK_COMPLETE`. Find the cause in the stack's **Events**, delete the stack, and launch it again with the same name.

The `VerifyAudience` output prints `pending-gateway-id`  
A stack update that changes the gateway, or its rollback, can leave the gateway's allowed audience at its placeholder, and every tool call then fails. Reset it to the gateway's ID. The reset is an `UpdateGateway` call, so it raises a change alert. The person who runs it needs `bedrock-agentcore:GetGateway` and `bedrock-agentcore:UpdateGateway` on the gateway, and `iam:PassRole` on the gateway's service role. `UpdateGateway` replaces the whole configuration, so these commands read the gateway, change only the audience, and send every field back. Expand the block that follows, copy it, and paste it at the prompt; it asks for the Region and the stack name:

### The script that sets the gateway's audience
<a name="real-time-data-integration-code-script-that-sets-the-gateways-audience"></a>

```
(
  umask 077; D=$(mktemp -d); trap 'rm -rf "$D"' EXIT
  R=${AWS_REGION:-us-east-1}
  printf 'Region of the stack [%s]: ' "$R"; read -r REGION; REGION=${REGION:-$R}
  printf 'Stack name [connect-sf-real-time]: '; read -r STACK; STACK=${STACK:-connect-sf-real-time}
  aws cloudformation describe-stacks --region "$REGION" --stack-name "$STACK" --query 'Stacks[0].StackStatus' --output text > /dev/null \
    || { echo "No stack named $STACK in $REGION. Check the stack name and the Region."; exit 1; }
  G=$(aws cloudformation describe-stacks --region "$REGION" --stack-name "$STACK" \
    --query "Stacks[0].Outputs[?OutputKey=='GatewayId'].OutputValue | [0]" --output text) || exit 1
  aws bedrock-agentcore-control get-gateway --region "$REGION" --gateway-identifier "$G" --output json > "$D/gateway.json" || exit 1
  aws bedrock-agentcore-control update-gateway --generate-cli-skeleton input > "$D/fields.json"
  python3 -I - "$D" "$G" <<'PY' || exit 1
import json, sys
d, gateway_id = sys.argv[1], sys.argv[2]
gateway = json.load(open(d + "/gateway.json"))
fields = json.load(open(d + "/fields.json"))
gateway["authorizerConfiguration"]["customJWTAuthorizer"]["allowedAudience"] = [gateway_id]
update = {k: v for k, v in gateway.items() if k in fields and v is not None}
update["gatewayIdentifier"] = gateway_id
json.dump(update, open(d + "/update.json", "w"))
PY
  aws bedrock-agentcore-control update-gateway --region "$REGION" --cli-input-json "file://$D/update.json" \
    --query status --output text
)
```

Run the `VerifyAudience` command again; it prints the gateway's ID.

The stack fails at the token refresh, with Salesforce's HTTP status and error code in the stack events  
The stack gets its first Salesforce token while it deploys, and fails if Salesforce refuses. Check the consumer key, the consumer secret and the key that holds it in your secret, and that the External Client App has the client credentials flow enabled with the integration user as its Run As user. The token check in Step 2 tests all of these; run it again and fix what it reports.

Registering the gateway fails: the access URL must be a valid gateway URL  
Check that the gateway still has its protocol configuration. A gateway update that leaves the protocol settings out removes them.

## Upgrading the template
<a name="real-time-data-integration-troubleshoot-upgrade"></a>

These are the messages the upgrade script in [Upgrade with the script](real-time-data-integration-update.md#real-time-data-integration-update-script) prints when it stops.

`The stack already runs the latest version; nothing changed.`  
There is nothing to upgrade.

`The stack is` followed by a status  
Nothing changed. Wait until the stack shows `CREATE_COMPLETE`, `UPDATE_COMPLETE` or `UPDATE_ROLLBACK_COMPLETE` in the CloudFormation console, then run the script again. If the stack shows `UPDATE_ROLLBACK_FAILED`, follow [If the upgrade fails](real-time-data-integration-update.md#real-time-data-integration-update-fails) first.

`Download failed` or `doesn't match its checksum`  
Nothing changed. Run the script again. If it fails again, download the files as [Template downloads](real-time-data-integration-deployment.md#real-time-data-integration-downloads) describes and check them by hand. If they still don't match, contact AWS Support before you deploy.

`AccessDenied` from `list-role-policies`, `get-role-policy` or `put-role-policy`  
You can't read or change the deployer role's inline policy. Ask an IAM administrator to run the script, or to give you the rights that [Upgrade with the script](real-time-data-integration-update.md#real-time-data-integration-update-script) lists. If it fails at `put-role-policy`, the change set stays on the stack's **Change sets** tab and the stack is unchanged; delete the change set there.

`The role` followed by a name and `has no inline policy`, or `Enter one of:`  
Nothing changed. The script writes the deployer policy only to an inline policy that the role already has. Run it again and enter one of the names it lists. If the role has no inline policy, attach the deployer policy to it inline as [CloudFormation template reference](real-time-data-integration-deployment.md) describes.

`The change set failed:` followed by a reason  
The script deleted the change set, and the stack is unchanged. Correct the cause the reason names, and run the script again.

`The update would or might replace:` followed by resource names  
The script deleted the change set, and the stack is unchanged. Don't upgrade this stack: a replaced gateway gets a new ID, which changes every tool name your flows call, and a replaced flow or view gets a new ARN. No update within 1.x replaces these, so contact AWS Support.

`Not run; the stack is unchanged.`  
You didn't answer `y`. The change set stays on the stack's **Change sets** tab. Delete it there, then run the script again when you're ready.

`The update failed`  
The stack rolled back. Follow [If the upgrade fails](real-time-data-integration-update.md#real-time-data-integration-update-fails).

`The AI console steps failed; run the console steps script with set.`  
The update finished, but the AI console steps didn't. The lines above the message name the cause. Run the console steps script with **set**, and see the console steps entries in [Self-service and the Connect assistant](#real-time-data-integration-troubleshoot-assistant).

`Gateway audience:` with a value other than the gateway's ID, or `Couldn't read the gateway`  
Run the command in the stack's `VerifyAudience` output. If it doesn't print the gateway's ID, tool calls fail; see the `VerifyAudience` entry in [Deploying and updating the stack](#real-time-data-integration-troubleshoot-deploy).

## Testing in the agent workspace
<a name="real-time-data-integration-troubleshoot-agent"></a>

The test setup script prints `STOPPED`  
The line says why. When a name belongs to someone else, the password doesn't meet the rules or the instance isn't found, the script stops before it creates anything. A `couldn't read`, `couldn't create` or `couldn't update` line can come after the script has created some resources. After you fix the cause, run it again; it reuses what it created.  
+ `already exists and this script didn't create it`: a user with that username, or a resource named `rtdi-test-queue`, `rtdi-test-routing`, `rtdi-test-agent` or `rtdi-modern`, exists without the script's `rtdi-test-setup` tag. For a user, run the script again with a new username. On an instance that signs users in through SAML or a directory, name a user who exists in your identity provider or directory but isn't yet a Connect Customer user. For another resource, set up the test agent in the admin website instead.
+ `the password needs`: enter a password of 8 to 64 characters, with an uppercase letter, a lowercase letter and a number.
+ `no instance named` or `no instances in`: the instance is in another Region, or the alias is misspelled.
+ `couldn't read`: the AWS CLI error printed above the line names the call that failed. An `AccessDeniedException` means your IAM identity lacks that Connect Customer permission.
+ `couldn't create the user`: the error above the line says why. Common causes are a username already used in your identity provider or directory, a user on a SAML or directory instance who doesn't exist there, the instance's users quota, or a missing `connect:CreateUser` permission. Fix the cause and run the script again, or run it with a new username.
+ Another `couldn't create` or `couldn't update`: the error above the line names the call and the reason, such as an `AccessDeniedException` or a quota.
The script calls these Connect Customer actions, each with the prefix `connect:`:  
+ To read: `ListInstances`, `DescribeInstance`, `ListQueues`, `ListRoutingProfiles`, `ListRoutingProfileQueues`, `ListSecurityProfiles`, `ListUsers`, `ListWorkspaces`, `ListWorkspacePages`, `ListHoursOfOperations` and `ListTagsForResource`.
+ To create: `CreateQueue`, `CreateRoutingProfile`, `AssociateRoutingProfileQueues`, `CreateSecurityProfile`, `CreateUser`, `UpdateUserRoutingProfile`, `UpdateUserSecurityProfiles`, `CreateWorkspace`, `CreateWorkspacePage`, `UpdateWorkspaceVisibility`, `AssociateWorkspace` and `TagResource`.
+ To remove, with **remove**: `DeleteWorkspace`, `DeleteUser`, `DeleteSecurityProfile`, `DeleteRoutingProfile` and `DeleteQueue`.

The test setup script prints `NOT DONE: add the Modern layout in the admin website`  
Connect Customer didn't accept the Agent Workspace page for `rtdi-modern` through the API; the error above the line says why. On some instances the page is available only in the admin website. Everything else is set up, and the script still prints the `Test queue ARN` line. In the Connect Customer admin website, choose **UI Management**, **Workspaces** and `rtdi-modern`. In the **Pages** section, choose **Add page** and **Use existing Connect page**. For **Page**, choose **Agent Workspace**; for **Page layout**, **Agent Workspace - Modern**; and for **View version**, **1**. Choose **Save**. The workspace is already visible only to the test agent and assigned to it.

The test setup script prints `NOT DONE` with a count of resources  
With **remove**, the script couldn't read or delete each resource that has a `Failed` line, and it counts each one. The AWS CLI error above that line names the call and the reason, such as a missing `Delete` or `ListTagsForResource` permission. Fix it and run the script with **remove** again; it skips what it already deleted.

Tools are listed, but calls fail  
Check the integration user's object and field permissions in the system. For Salesforce, run the Step 2 setup script again with the same values and read its `FAIL` lines.

The guide shows a message such as **No record matches this contact.**, **Could not load** or **Case not confirmed**  
See the causes and checks in [Messages agents might see](#real-time-data-integration-messages).

Every contact shows **This contact's record could not be looked up.**  
The lookup fails on every contact, for example during a Salesforce or gateway outage, or after the integration user's access changed. Agents can choose **Try again**, which runs the lookup again, or search for the customer. Check the stack's health dashboard and the **Tool calls failing** alarm; see [Running the integration](#real-time-data-integration-troubleshoot-dashboard).

The chat is missed, or the agent can't accept another contact until a chat is closed  
In Test chat, **Apply** starts the chat at once, and Test Settings stay set, so opening Test chat again can start another chat. The chat is offered to the agent. In the agent workspace, choose **Close contact** for a missed chat, then test again with the agent workspace tab open.

The External Tool block shows no tools  
Check that the gateway is registered as an **MCP server** integration, that the target is `READY`, and in the gateway, that **Supported Versions** includes `2025-03-26`, that **Allowed audiences** includes the gateway ID, and that the **Discovery URL** is your instance URL followed by `/.well-known/openid-configuration`.

The guide shows an error instead of the record  
Check that the contact has the record ID the guide expects, that the integration user can read the record, and that the call returns within 8 seconds and under 32 KB.

A case's status in Salesforce differs from what the agent set, or its owner changed  
Check the integration user's edit access to the case, validation rules such as one that requires a reason to close, and assignment rules, which can change the owner on a case update; see [Update records and run automation in your system](real-time-data-integration-automation.md).

## Running the integration
<a name="real-time-data-integration-troubleshoot-dashboard"></a>

To monitor the integration, use the stack's health dashboard; see [Monitor the integration](real-time-data-integration-maintain.md#real-time-data-integration-monitor). For details on gateway metrics, logs and debug messages, see [AgentCore generated gateway observability data](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/observability-gateway-metrics.html). 

Tool calls fail after you rotate the secret, revoke it, or end the integration user's sessions  
The gateway sends the token the token refresh function last stored, and the function runs every five minutes. Run it at once, as in [Rotate the credentials](real-time-data-integration-maintain.md#real-time-data-integration-rotate).

The dashboard's **Salesforce token refreshes** tile is at 0, or the token refresh alarm fires  
The stack can't sign in to Salesforce. Check the token refresh function's log for Salesforce's error code: a changed consumer secret, or a disabled client credentials flow.

The **Salesforce API allowance left** tile is near 0, or the Salesforce API allowance alarm fires  
Reduce calls, or ask Salesforce about the org's allocation. For what happens when your org reaches its allocation, see [API Request Limits and Allocations](https://developer.salesforce.com/docs/platform/salesforce-app-limits-cheatsheet/guide/salesforce-app-limits-platform-api.html) in the Salesforce documentation.

The **Tool calls succeeding** tile is below 95 percent, or the tool calls failing alarm fires  
Check the dashboard's gateway errors and Salesforce time. User errors include calls Salesforce refused.

## Targets you add
<a name="real-time-data-integration-troubleshoot-targets"></a>

A target you added with an OAuth client does not reach `READY`  
For the stack's own Salesforce target, wrong credentials fail the stack at the token refresh instead; check the consumer key, secret and Run As user. For a target you added, check the system's domain and the credentials. For Salesforce, check the My Domain URL you entered, and that **Run As** is set on the External Client App, and run the token check in [Step 2: Create a Salesforce integration user and External Client App](real-time-data-integration-credentials.md) again.

An MCP server target fails with an authorization error  
For a Salesforce hosted MCP server, check the External Client App against [Create an External Client App](https://developer.salesforce.com/docs/platform/hosted-mcp-servers/guide/create-external-client-app.html) in the Salesforce hosted MCP servers documentation.

A target you added with an OAuth client fails with an error parsing the client credentials response  
Leave the target's scopes empty, and set the scopes on the External Client App instead. The same error can appear when a target with an OAuth client requests a new token on every tool call under load: see the warning in [Connect through an MCP server](real-time-data-integration-mcp.md).

## Salesforce tool calls
<a name="real-time-data-integration-troubleshoot-tools"></a>

The following topics cover the operations of the stack's `salesforce` target.

### Record reads and writes
<a name="real-time-data-integration-troubleshoot-records"></a>

A get operation returns fields you didn't ask for, or not a field you asked for  
The get operations return the fields in `fields` that the integration user can read. Without `fields`, Salesforce returns every field the user can read. A field the user can't read is left out. Give the user read access to the field, then call again.

A call fails with `ENTITY_IS_LOCKED`  
The record is in an approval process that locks it. The integration can't edit the record until the approval finishes. For who can edit a locked record, see your approval process's record editability setting in Salesforce.

A call fails with `pattern validation failed`  
Each record ID must be 15 or 18 letters and digits, and each object, flow and action name must be letters, digits and underscores. The gateway rejects any other value before it calls Salesforce, so a value can't reach another Salesforce resource. Pass the record ID or API name only.

### Custom fields
<a name="real-time-data-integration-troubleshoot-custom-fields"></a>

`createCase` or `updateCase` doesn't set a custom field  
These operations send only the standard Case fields that their schema lists, and drop other fields. Use `createRecord` or `updateRecord` with the field in `body`, for example `{"objectName": "Case", "id": "{{case-id}}", "body": {"Created_By_Connect__c": true}}`, or generate typed operations; see [Add your own Salesforce operations](real-time-data-integration-salesforce.md#real-time-data-integration-custom-operations).

A new custom field can't be read or written  
The permission set grants access to the fields that existed when you last ran the setup script. Run the script again after you add a field.  
The script grants access only to fields that the admin who runs it can access. Check that your admin profile has access to a new field before you run the script. If it doesn't, give your admin profile or permission set access to the field, then run the script.

### Flows
<a name="real-time-data-integration-troubleshoot-flows"></a>

`runFlow` runs autolaunched flows. The following table shows which flow types a guide or AI agent can run.


**Flow types and runFlow**  

| Flow type | How it runs | 
| --- | --- | 
| Autolaunched | With `runFlow`. | 
| Screen | Not through the gateway: it needs the Salesforce user interface. To use the same logic from a guide, run it in an autolaunched flow, and show its inputs and result in the guide's views. | 
| Record-triggered | Runs when the gateway creates or updates the record, as it does for any user. No call is needed. | 
| Scheduled | Not through the gateway: Salesforce runs it on its schedule. | 

`runFlow` fails  
Check that the flow is active and autolaunched, and that the integration user has the **Run Flows** permission and access to the objects the flow uses. Call `describeFlow` for the flow's input variable names, and pass them as `{"inputs": [{"{{variable}}": {{value}}}]}` in `body`.

### Apex actions
<a name="real-time-data-integration-troubleshoot-apex"></a>

`runApexAction` returns `An internal error occurred`  
The most common cause is that the integration user can't access the Apex class. Add the class to the setup script's `apexClasses` list and run the script.

### Quick actions
<a name="real-time-data-integration-troubleshoot-quick-actions"></a>

`runQuickAction` fails for an action that `listQuickActions` lists  
`listQuickActions` shows an object's actions as `{{Object}}.{{Action}}`, such as `Case.{{ActionName}}`. Pass the name without the object prefix, `{{ActionName}}`, with `objectName` set to the object.

### Approvals
<a name="real-time-data-integration-troubleshoot-approvals"></a>

A record can't be edited after `submitApproval`  
The approval process locks the record while it waits for approval, according to its record editability setting. Edits fail with `ENTITY_IS_LOCKED` until the approval finishes.

### Platform Events
<a name="real-time-data-integration-troubleshoot-events"></a>

Publishing a Platform Event fails  
Publish with `createRecord`, with `objectName` set to the event's API name, which ends in `__e`, and the event's fields in `body`. The integration user needs Create on the event: add it to the setup script's `objects` map, for example `'Order_Event__e' => 'read,create'`.

Salesforce events need to reach AWS  
The gateway only sends calls to Salesforce; it doesn't receive events. To send Platform Events or change data capture events from Salesforce to AWS, use Salesforce Event Relay with Amazon EventBridge, which you set up separately.

### Response size
<a name="real-time-data-integration-troubleshoot-size"></a>

A call works outside the guide but takes the External Tool block's error branch  
The External Tool block fails a call whose result is over 32 KB. For example, `describeObject` on Case can return more than 32 KB. Use `getRecord` or another get operation with a `fields` list, which returns only the fields you name.

## Self-service and the Connect assistant
<a name="real-time-data-integration-troubleshoot-assistant"></a>

The console steps script offers a different Self service default  
The script checks the assistant's current **Self service** default first, and offers:  
+ The same AI agent's latest version, when the default is one of the stack's AI agents at an older version, as after an update, or at no version.
+ The knowledge agent's latest version, when the default names an AI agent or a version that the assistant no longer has.
+ **keep**, which changes nothing, when the default is another AI agent that the assistant still has.
It refuses to set an AI agent that has no published version.

The create or update fails at `AiAssistantAssociation`  
**Existing Connect assistant (ARN)** was empty on an instance that already has an assistant, and an instance can have only one assistant association. The instance's assistant can be one that an earlier failed create of this stack kept, `{{stack-name}}-assistant`. Run the assistant check script, and try again with the ARN it prints in **Existing Connect assistant (ARN)**. See [Choose the assistant and the knowledge base](real-time-data-integration-ai-setup.md).  
Don't delete an assistant that is still associated with the instance. To delete a `{{stack-name}}-assistant` that you don't use, first remove its association with the instance, if it has one, and then delete the assistant.

The create or update fails at `AiKnowledgeBase`  
The knowledge base in **Knowledge base to associate (ARN)** is already associated with the assistant. Leave the field empty: the AI agents search every knowledge base the assistant has.  
If the message is `Update operation is not supported`, the update changed the stack's own tags. CloudFormation copies stack tags to every resource, and the knowledge base association can't be updated in place, so the update and its rollback both fail. On a stack with a knowledge base, keep the stack's tags unchanged. To recover, in the CloudFormation console choose **Stack actions**, **Continue update rollback**, and skip `AiKnowledgeBase`; the association stays in place. Then run the update again with the stack's tags unchanged.

Self-service answers from the instance's previous assistant  
The stack's Lex bot keeps the assistant it was built with. After you associate a different assistant with the instance, run the console steps script with **remove**, then delete the stack and create it again with the new assistant's ARN in **Existing Connect assistant (ARN)**. A stack update that changes only **Existing Connect assistant (ARN)** doesn't change the bot.

The assistant check script prints `NO KNOWLEDGE BASE`, or an article isn't `ACTIVE`  
Integrate a knowledge base with the assistant; see [Initial setup for AI agents](ai-agent-initial-setup.md). An article with a status other than `ACTIVE` is still indexing; run the script again until it shows `ACTIVE`.

The console steps script prints `Stack ... has no ConnectAssistantStatus output`, or `Can't read stack`  
The stack name or the Region is wrong, or the stack runs the gateway-only template, which has no AI self-service flow. Run the script again with the stack's name and Region.

The console steps script prints `No security profile` or `No published version`  
The stack's AI agent or its security profile isn't in the instance, for example because the stack's create or update hasn't finished. Wait until the stack shows `CREATE_COMPLETE` or `UPDATE_COMPLETE`, and run the script again. An `AccessDeniedException` means your AWS sign-in lacks an action from [Before you begin](real-time-data-integration-ai-agents.md#real-time-data-integration-ai-prerequisites); ask your AWS administrator.

The AI agent says it is having trouble for every question, or the chat goes to an agent right after the first question  
The AI agent version in use has no security profile, so every tool call fails, including the knowledge base search. Run the console steps script with **set**; see [Finish the AI setup after each create or update](real-time-data-integration-ai-console.md). Run it after every create or update.

The AI self-service flow's contacts get another AI agent than the stack's  
The assistant's **Self service** default is still the AI agent it had before. Set it to the knowledge agent with the console steps script.

Agent assist answers from the knowledge base but can't find the customer or create a case  
The agent's own security profile doesn't list the module in the **Flow modules** section of its **Edit** page, or the contact started before you saved that change, or it didn't come through the AI self-service flow. Start a new contact after the change. See [Give agents agent assist in the agent workspace](real-time-data-integration-ai-assist.md).

The stack delete fails with `DELETE_FAILED` on a security profile  
The profile is still associated with an AI agent. Run the console steps script with **remove**, then delete the stack again.

The Connect assistant panel suggests nothing until the agent asks  
The panel answers only questions agents type. Agents type their question in **Ask a question**.

## Removing the integration
<a name="real-time-data-integration-troubleshoot-removal"></a>

**Delete** is missing for the External Client App  
The app's row in **External Client App Manager** has only edit and disable options. Open the app; **Delete** is in the menu next to **Disable**.

The integration user can't be deleted  
Deactivate the user in Setup, **Users**; the removal script does this.

Test records stay in Salesforce after removal  
Removing the integration doesn't delete records the guide created. Delete test accounts, cases and case comments in Salesforce. The test contacts stay in Connect Customer's contact records.

## Messages agents might see
<a name="real-time-data-integration-messages"></a>

These messages come from the Salesforce account and case guide. Guides you build for other systems can follow the same pattern. If a system is slow or down, the Connect Customer contact details stay on screen and the agent keeps helping the customer.


**Messages in the account and case guide**  

| Message | Usual cause | What to check | 
| --- | --- | --- | 
| **Customer not found** or **Unknown caller**, with **No record matches this contact.** | The record ID or the lookup value is missing or wrong, or the integration user cannot see the account. The agent can find the account with a search. | The contact attributes in [How the guide finds the record](real-time-data-integration-start.md#real-time-data-integration-find-record), such as `accountId`, and account sharing for the integration user. Check that your inbound flow sets `customerContactId` to `$.ContactId` before it sets the guide flow. | 
| **Customer not found** or **Unknown caller**, with **This contact's record could not be looked up. Search for the customer.** and **Try again** | The lookup didn't run: the Find the record module, or its call to Salesforce through the gateway, failed, for example during an outage. **Try again** runs the lookup again; the agent can also search. | The stack's health dashboard and the **Tool calls failing** alarm; see [Running the integration](#real-time-data-integration-troubleshoot-dashboard). With your own Find the record module, check its error branches. | 
| **Some of this case is not shown**, in the case view | The case view's full read failed, because the case and its related lists are over 32 KB or the integration user can't read one of its related lists, so the view leaves out the description and related lists. **Refresh** tries again. When every case opens this way, it is the integration user's access. | That the integration user has **Access Activities** (run the Step 2 script again; it prints `PASS Access Activities`), and that it can read the case's emails and files. See [The case view](real-time-data-integration-agent-experience.md#real-time-data-integration-agent-case-view). | 
| **Could not load**, with **The customer's details could not be loaded.** | The call failed, took longer than 8 seconds, or returned more than 32 KB. The system's API limit might be used up. | Flow logs, gateway errors and throttles, and API usage in the system. | 
| **Case not confirmed** | The integration user cannot create the case, a validation rule blocked it, or the write was slow. | Choose **Back to the account**, which reloads the **Cases** list, and check it for the case before creating another: it may still have been saved. | 
| **Update case** says that the case shows a status other than the one picked, that the save was not confirmed, or **Your comment was not confirmed.** | No edit access to that case, or a validation rule blocked the change. | Case sharing and rules, such as one that requires a reason to close. Check the case before the agent saves a comment again: it may already be saved. | 
| **These details changed in Salesforce after the guide last read them, so nothing was saved.** | Someone changed the account or contact in Salesforce after the guide last read it, so Update a record wrote nothing. | Nothing: the agent opens **Edit** again, which shows the latest details. | 
| **Salesforce did not save the changes. The details you entered are kept.** | Salesforce refused the update, for example because of a validation rule or the integration user's field access. | The text after **Salesforce's message:** on the form, and the integration user's edit access to the Account and Contact fields. | 
| **These details can't be saved from here.** | Update a record refused the save before it called Salesforce: the contact is no longer on this account, the record's ID isn't valid, or a value holds a character the module refuses. | The agent corrects the values and saves again, or chooses **Cancel**, which reads the account again. | 
| **Check the email address: it needs an @. The details you entered are kept.** | The email has no @. The **Email** box normally catches this before **Save**. | The agent corrects the email and chooses **Save** again. | 
| **The changes were not confirmed. Check the details shown before you edit again.** | The guide got no answer it could read from Update a record, for example because the write was slow. The changes may have been saved. The guide reads the account again and shows it. | The agent compares the details shown with the changes before editing again. | 
| **Status not saved**, with **That status isn't one of this org's case statuses. Pick one from the list.** | In **Update case**, the picked status didn't match one of the org's case statuses that the guide read. | The agent picks a status from the list and chooses **Save** again. | 
| **The case could not be loaded.** | The call for the case view failed, or the integration user cannot see the case. | Case sharing for the integration user, and the same checks as for **Could not load**. | 
| **Check the phone in New customer: digits only, the 10-digit number with no spaces, dashes, brackets or \+1. The details you entered are kept.** | The phone isn't a 10-digit North American number. | Nothing: the agent corrects the phone and saves again. | 
| **Enter the account name, first name and last name in New customer, with no { or @{ in any detail. The details you entered are kept.** | A detail holds `{` or `@{`, or the account name, the first name or the last name is only `-` or the word `null`. | Nothing: the agent corrects the details and saves again. | 
| **Enter an email or a phone in New customer. The details you entered are kept.** | Both the email and the phone are empty. | Nothing: the agent enters one and saves again. | 
| **Customer created**, with **The case wasn't created:** and Salesforce's reason | Salesforce refused the first case. The account and contact were created. | Salesforce's reason. The agent creates the case from the **Create case** form shown, or chooses **Back to the account**. | 
| **The case may have been created. Check Recent cases before creating it again.** | The guide couldn't confirm the first case of **New customer**. | **Recent cases** on the new account, before creating the case again. | 
| **Enter the first name and the last name. Open Add a contact and enter the details again.** | In **Add a contact**, a first or last name is only `-` or the word `null`. | Nothing: the agent enters the names again. | 
| **Check the email address: it needs an @. Then open Add a contact and try again.** | In **Add a contact**, the email has no @. | Nothing: the agent corrects the email. | 
| **The details cannot hold {. Then open Add a contact and try again.** | In **Add a contact**, a name holds `{`. | Nothing: the agent removes it. | 
| **The contact was not confirmed. If it isn't in the list, check the details and add it again.** | The guide couldn't confirm the new contact. | **Contacts** on the account, before adding the contact again. | 
| **The case could not be loaded after your update.** | An **Update case** save wasn't confirmed, and the case couldn't be read again. | The case, before the agent saves again: the update may already be saved. | 
| **Wrap-up not saved**, with **Try again** and **Done** | The wrap-up's save failed. | The agent chooses **Try again** or **Done**. | 
| **A matching customer already exists, and nothing was created. This is the matching account.** | **New customer** found a contact with the same email address or phone number, and the guide opened its account. | Nothing: the agent works on the matching account. | 
| **A matching customer already exists, and nothing was created. Search for it, or change the details.** | **New customer** found a match, but the match has no account to open. | The agent searches for it. | 
| **Check the email address in New customer: it needs an @. The details you entered are kept.** | In **New customer**, the email has no @. | Nothing: the agent corrects the email and saves again. | 
| **The duplicate check did not run, and nothing was created. Open New customer and try again.** | The check for an existing customer failed, so **New customer** created nothing. | The agent opens **New customer** and tries again. | 
| **The customer was not confirmed before the time limit and may have been saved. Search for it before you create it again.** | Create a customer didn't answer in time, and the guide found no saved customer by its email. | The agent searches for the customer before creating it again. | 
| **The customer may have been saved before the time limit. Check it, then create the case.** | Create a customer didn't answer in time, and the guide found and opened a customer with that email. | The account shown, before creating the customer or the case again. | 
| **The customer was saved, but the account could not be opened. Search for it.** | The customer was created, but the guide couldn't read the new account's ID. | The agent searches for the customer before creating it again. | 