
Agentforce gives you the flexibility to design intelligent chat assistants that respond differently based on your users' inputs and business logic. Two powerful tools that help make this happen are Context Variables and Custom Variables.
In this blog, we’ll break down what each of these are, how they work, and how to use them effectively in your Salesforce org to fine-tune your agent's behavior and decision-making flow.
Think of them as hidden tools behind the scenes helping your agent know what to do and when to do it.
What Are Context and Custom Variables?
Context and Custom Variables help you manage your assistant’s logic and response flow based on specific user actions, stages in the conversation, or system-level triggers.
Let’s understand both one by one:
Context Variables
Context Variables are built-in system variables provided by Salesforce that track the current state of the conversation and what the user is trying to do.
You don’t need to manually create these — they’re already available for use in your conditions, filters, and logic branches.
Some commonly used context variables include:
| Context Variable | Description |
|---|---|
| CurrentIntent | The latest intent detected in the user’s message |
| CurrentEntityValues | Extracted entities from the user’s request |
| UserInput | Raw text input from the user |
| PreviousIntent | Intent from the previous message |
| SessionId | Unique ID for the user’s chat session |
Use Case Example: If CurrentIntent is “Check Order Status”, you can tell the assistant to guide the user to the Order Info screen.

Custom Variables
While context variables are predefined, Custom Variables are created by you — the developer or admin — to track any custom data you need across the conversation.
They’re super useful when you want to:
- Store values the user enters (like email, phone, product name)
- Save system values returned from Flows or Apex Actions
- Use your own business logic for branching the flow
Custom variables must be manually defined in the assistant setup.
You can name them anything meaningful like:
- userEmail
- isVerified
- productName
- accountType

How Do Variables Work in Action?
Let’s walk through a practical example.
Imagine a customer is chatting with your assistant and asks:
"Can you check my support case status?"
Here’s what happens:



