

# Update records and run automation in your system

A guide starts logic in the connected system in two ways, both run as the integration user.

**Automation on the guide's writes.** When the guide creates or updates a record, any automation your system runs when a record changes runs on the guide's writes too. In Salesforce, that includes record-triggered flows, Apex triggers, and validation and assignment rules; for the order in which they run, see [Triggers and Order of Execution](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_order_of_execution.htm) in the Salesforce documentation. With Salesforce, keep these behaviors in mind:
+ **Assignment rules and case updates.** The CloudFormation template's `updateCase` sends no assignment rule header. For how Salesforce applies assignment rules to a REST update with no header, see [Assignment Rule Header](https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/headers_autoassign.htm), and test a status change on a test case to check whether the owner changes. To keep the guide's updates out of an assignment rule, add criteria to its rule entries that exclude the integration user.
+ **Automation sees the integration user.** A rule, flow or Apex that reads the current user evaluates the integration user, not the agent.

**Actions the guide calls.** For logic that doesn't start from a record change, the guide calls an operation of your system's target that starts it. With Salesforce, call `runFlow`, `runApexAction`, `runStandardAction`, `runQuickAction` or `submitApproval` on the stack's `salesforce` target, as the following table shows; for a worked example, see [Start your system's automation from the guide](real-time-data-integration-run-automation.md). A stack update replaces changes to that target, so add other operations as your own target; see [Add your own Salesforce operations](real-time-data-integration-salesforce.md#real-time-data-integration-custom-operations). See also [Security considerations](real-time-data-integration-security.md). For the permissions each action needs, see [Salesforce tool calls](real-time-data-integration-troubleshoot.md#real-time-data-integration-troubleshoot-tools).


**Salesforce actions a guide can call**  

| Action | Operation | What to know | 
| --- | --- | --- | 
| Autolaunched flow | `runFlow` | Runs one active autolaunched flow and returns its output variables. | 
| Submit for approval | `submitApproval` | The submitter is the integration user. The approval process can lock the record. | 
| Send email, post to Chatter | `runStandardAction` with `emailSimple` or `chatterPost` | The call runs as the integration user. For the sender address and the limits that apply, see [Simple Email Actions](https://developer.salesforce.com/docs/atlas.en-us.api_action.meta/api_action/actions_obj_email_simple.htm) in the Salesforce documentation. | 
| Quick action | `runQuickAction` | Takes the action name without the object prefix. | 
| Invocable Apex | `runApexAction` | The integration user needs access to the Apex class. | 
| Apex REST | Your own target; see [Add your own Salesforce operations](real-time-data-integration-salesforce.md#real-time-data-integration-custom-operations) | Needs a target whose server is `/services/apexrest`. Whether the class enforces the integration user's object and field permissions depends on how it is written; see [Using the with sharing, without sharing, and inherited sharing Keywords](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_keywords_sharing.htm) in the Salesforce documentation. | 
| Platform Event | `createRecord` with an `objectName` ending in `__e` | The call confirms only that the event was published; the subscriber's outcome doesn't come back to the agent. | 

Each call counts toward the org's API 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.

A slow flow can finish after the External Tool block's 8-second limit, when the guide already shows an error. So make flows and Apex check for work already done.

An action can report a failure in its result. To catch it, a guide flow reads the action's result from `$.ExternalTool.ResultData`, as the template's flows read each `composite` step's `httpStatusCode`. It then branches on a field such as `isSuccess` with a **Check contact attributes** block. Without that check, an action that reports a failure looks successful to the flow.

**Screen flows.** The actions resource doesn't run screen flows. To use a screen flow's logic from a guide, run it in an autolaunched flow, and show its inputs and result as views in the guide.

The connected system records the integration user, not the agent, as the creator of every record the guide writes, and in Salesforce as the owner unless an assignment rule changes it. To find the agent, match the record to the Connect Customer contact record. When the agent creates a case from the account view's **Create case** card, the guide saves the new case's ID in the contact attribute `newCaseId`. To record the agent in your system as well, see [Record the agent in your system](#real-time-data-integration-run-automation-agent).

## Record the agent in your system
<a name="real-time-data-integration-run-automation-agent"></a>

Every call runs as the integration user, so your system's own audit fields, such as who created or last changed a record, show that user. To keep track of which agent made a change, store the agent's identity on the record as data, for example in a custom "handled by" field or in a comment.

Connect Customer flows expose the agent's identity as the Agent attributes `$.Agent.UserName` and `$.Agent.ARN`. The Connect Customer documentation lists them for whisper, hold and transfer-to-agent flows (see [List of available contact attributes in Connect Customer and their JSONPath references](connect-attrib-list.md)), so check that they hold a value in your guide flow before you rely on them. Choose the value to store:
+ **Username:** readable, and the same in your other reports if agents use one username across systems.
+ **Agent ARN.** Stable when a username changes, but differs in each Connect Customer instance.

Set the value in your own flow module from the Agent attribute, never from text the customer or agent types, and give AI agents the module rather than the raw operation, so no caller can choose the value. The stack's Create case, Update case and Update a record don't set custom fields, so write the field with `createRecord` or `updateRecord`; see [Add your own Salesforce operations](real-time-data-integration-salesforce.md#real-time-data-integration-custom-operations). When a self-service AI agent makes the change, there is no agent to record: store a fixed value, such as the AI agent's name. Check that the Agent attribute holds a value when agent assist runs the module. You can also match the stored value to the Connect Customer contact record, which identifies the agent who handled the contact (the user ID in the agent's ARN).