Use Custom Variables for Agentforce Service Email
Agentforce Service Agent now passes inbound email context, such as the Case ID, into custom variables instead of bundling it with the user message. You can reference these variables in your topics and action inputs for more reliable automation.
Required Editions
| Available in: Lightning Experience |
| Available in: Enterprise, Performance, Unlimited, and Developer Editions. Required add-on licenses vary by agent type. |
To learn about channel support for other agent types, see the documentation for that type. |
| User Permissions Needed | |
|---|---|
| To create email templates: | Lightning Experience User |
| To edit public email templates: | Modify All Data, Manage Public Lightning Email Templates, or template ownership |
| To create Agentforce Service Agent email configurations: | Manage Agentforce Service Agents AND Manage AI Agents OR Customize Application |
| To edit routing addresses: | Customize Application |
| To create Omni-Channel flows: | Customize Application |
Your agent must have the Service Email Connection enabled to receive inputs to these variables.
- New Agents: Agentforce Service Agents have these variables predefined.
- Existing Agents: You must manually add these variables to your agent configuration.
Manually Add Custom Variables
If you have an existing agent, follow these steps to ensure it can process email context correctly:
- In Setup, search for Agentforce Agents. Select your agent and click Open in Builder.
- Deactivate your Agent. You cannot modify custom variables while the agent is active.
- Click on the Context tab in the Builder.
- Click New Variable and create a new variable for each email context.
- Once all variables are added, click Save and then Activate.
| Name & API name | DescriptION | Data Type | set by Api | allow llm to use |
|---|---|---|---|---|
| emailCaseId | Stores the Salesforce Case ID created by an inbound email. | Text | True | True/False* |
| endUserEmail | Stores the email address of the person who sent the email. | Text | True | True/False* |
| endUserContactId | Stores the Salesforce Contact ID assocaited with the sender. | Text | True | True/False* |
Set "Allow LLM to use value" to True if you want the agent to reason with its data in its instructions, or False if it is only needed as an input for actions.
Best Practices for Topic Instructions
Update your Topic and Action configurations:
- Direct Mapping: In your Action inputs, map the input directly to the custom variable (e.g., map a "Close Case" action input to emailCaseId).
- Explicit Instructions: Update Topic instructions to say: "Use the emailCaseId variable to identify the current record," rather than searching the conversation history.



