Sub topic 6
Choosing data types and structure
This chapter covers how the type and shape of an action's inputs and outputs affect whether the agent can fill them and explain them. It assumes you can read basic Apex or build a Flow with variables. It also assumes you know what an Agentforce topic and action are, and that you've read the earlier chapters on names, labels, descriptions, and input design.
Why types matter to the agent
The agent is a language model. It doesn't see your Apex class or your Flow canvas. It sees the action's name, the label and description of each input and output, and a data type for each. It then writes a value for each input in a form that matches the type.
A type does two jobs:
- It limits what the platform will accept. A
Dateinput rejects text such as "next Tuesday", and a number input rejects "a few". - It tells the model what to produce. A
Booleanpushes it toward true or false, and anIntegertoward a whole number.
The more precisely a type matches the value, the less the description has to explain. A good description still adds the meaning of the value, its unit, and an example.
Common types and how the agent handles them
The exact list depends on the action target and your org's release. The builder shows what is available for each target. These are the types you will use most often.
| Type | Good for | Watch out for |
|---|---|---|
| Text (`String`) | Names, order numbers, free-form notes, codes | The agent can write anything, so validate in your code |
| Number (`Integer`, `Decimal`, `Double`) | Quantities, amounts, counts | State the unit, such as "in US dollars" or "in days" |
| Boolean | Yes/no choices such as "include cancelled orders" | The agent may guess when the user was silent. Say what the default is |
| Date, Date/Time | Delivery dates, ranges | Time zones for Date/Time. Prefer Date when the time of day doesn't matter |
| Record ID (`Id`) | A specific Salesforce record | The agent can't invent a valid ID. It must get it from an earlier action or the conversation context |
| Record (`sObject`) | Passing a whole record between actions | Large objects expose many fields the agent doesn't need |
| Collection (`List`) | Several values of one type | Harder to fill from conversation, and results can be long |
| Apex-defined or complex type | Grouped values with structure | Support differs by target and feature, and the agent reasons less reliably over it |
The next sections cover each of these choices in more detail.
Prefer the narrowest type that fits
Choose the type that rejects wrong values for you.
- Use
Datefor a date, notString. The platform handles the parsing, and your code doesn't need to handle "12/1", "1 Dec", and "2026-12-01". - Use
Integerfor counts. The model won't send "three" to a field that requires a whole number. - Use
Booleanfor a true/false switch, not a text field that expects "yes" or "no".
Don't over-narrow. A phone number is a String, because a number type drops leading zeros and plus signs. An order number such as 00000101 is a String for the same reason: it is an identifier, not a quantity. As a rule, if you would never add, average, or compare the values, use text.
Handling fixed choices
Apex invocable variables and many Flow variable types have no enumeration type. A value with fixed choices, such as an order status, is usually a text input. Two things make it reliable:
- List the allowed values in the description, in the exact spelling your code expects.
- Check the value in your code and return a clear message if it isn't allowed.
The first step reduces bad values. The second step handles the ones that still arrive. Don't rely on the description alone, because the model can paraphrase "Activated" as "Active".
Keep inputs flat
Each input should be one value the agent can get from the user in one step. A flat list of simple inputs works better than a single input that holds a structure:
- A
Start Dateand aStatusare easy to fill and easy to describe. - A single input that expects a JSON string with both is hard to describe. It also fails on the first typo in the JSON.
Complex types are sometimes right, for example when you pass a record the agent got from an earlier action to a later one. In that case the agent is moving a value, not composing one. Where the user must supply the data, keep it flat.
Shaping outputs
Output structure is a separate decision, because the agent reads outputs to write its reply. Outputs have these properties:
- Every output you return is available to the model. Many outputs, or a large collection, add noise and can push out more important context.
- Raw field names such as
Status__cmean little. A label and description turn them into something the agent can quote. - A collection of records forces the agent to decide which ones matter. If the action can decide that, it should.
Two patterns work well:
- Summarize in the action. Return a count and a short text summary of the top few results, rather than 200 records.
- Return a message field. A plain-language
messageoutput gives the agent a sentence it can rely on in all cases, including when no data is found. A later chapter covers error and empty-result handling in detail.
Choosing a shape
The diagram shows a simple way to choose between the shapes.
Example: typed inputs and a compact output
This Apex action finds a customer's recent orders. It uses a Date input, a text input with fixed choices that it validates, and a flat output with a count and a summary instead of a list of records. It also processes all requests with a single query, so it is safe when called in bulk.
public with sharing class FindRecentOrders {
private static final Set<String> ALLOWED_STATUSES = new Set<String>{ 'Draft', 'Activated' };
public class Request {
@InvocableVariable(
label='Start Date'
description='Earliest order date to include, as a calendar date such as 2026-11-01. Ask the customer if it was not given.'
required=true
)
public Date startDate;
@InvocableVariable(
label='Order Status'
description='Optional status filter. Allowed values are exactly Draft or Activated. Leave empty to include all statuses.'
)
public String status;
}
public class Response {
@InvocableVariable(
label='Order Count'
description='Number of orders found, up to 200. 0 if none match.'
)
public Integer orderCount;
@InvocableVariable(
label='Order Summary'
description='Up to five matching orders, one per line, with order number, date, and status. Empty if none match.'
)
public String summary;
@InvocableVariable(
label='Result Message'
description='A short plain-language message describing the outcome, including invalid filters and no matches.'
)
public String message;
}
@InvocableMethod(
label='Find Recent Orders'
description='Lists orders on or after a start date, optionally filtered by status. Use when the customer asks about recent orders and has no specific order number.'
)
public static List<Response> find(List<Request> requests) {
Date earliest = null;
for (Request r : requests) {
if (r.startDate != null && (earliest == null || r.startDate < earliest)) {
earliest = r.startDate;
}
}
List<Order> orders = new List<Order>();
if (earliest != null) {
orders = [
SELECT OrderNumber, EffectiveDate, Status
FROM Order
WHERE EffectiveDate >= :earliest
WITH USER_MODE
ORDER BY EffectiveDate DESC
LIMIT 200
];
}
List<Response> results = new List<Response>();
for (Request r : requests) {
Response res = new Response();
res.orderCount = 0;
if (r.startDate == null) {
res.message = 'A start date is required.';
} else if (String.isNotBlank(r.status) && !ALLOWED_STATUSES.contains(r.status)) {
res.message = 'Status must be Draft or Activated, but was ' + r.status + '.';
} else {
List<String> lines = new List<String>();
for (Order o : orders) {
Boolean dateOk = o.EffectiveDate >= r.startDate;
Boolean statusOk = String.isBlank(r.status) || o.Status == r.status;
if (dateOk && statusOk) {
res.orderCount++;
if (lines.size() < 5) {
lines.add(o.OrderNumber + ', ' + String.valueOf(o.EffectiveDate) + ', ' + o.Status);
}
}
}
res.summary = String.join(lines, '\n');
res.message = res.orderCount == 0
? 'No orders were found on or after ' + String.valueOf(r.startDate) + '.'
: res.orderCount + ' order(s) found.';
}
results.add(res);
}
return results;
}
}Points to notice:
startDateis aDate, so the platform handles the conversion from what the user said.statusis text, so the code checks it againstALLOWED_STATUSESand returns a message the agent can pass on.- The output holds a count, a bounded summary, and a message. It doesn't hold a list of
Orderrecords. orderCountis always set, so the agent never sees a missing count and has to guess what it means.
Typing choices in a Flow
In a Flow action, the agent sees the variables marked as available for input and available for output. The same rules apply:
- Create one variable per fact, with the narrowest data type that fits.
- Give each variable a clear description. The description is the agent's only explanation of it.
- Mark a variable available for input only if the agent should set it, and available for output only if the agent should read it. Internal working variables stay hidden.
- Avoid a record variable for output when two or three text or number variables would do. A record output exposes every field it holds.
Common mistakes
- Using a text type for a date. The agent writes dates in inconsistent formats and your parsing breaks.
- Using a number type for an identifier. Leading zeros are lost.
- Leaving a Boolean unexplained. A Boolean named "Include Closed" needs a description that says what happens when the user doesn't mention it.
- Returning whole records. The agent gets many fields it doesn't need, and may mention one in its answer.
- Returning a null where a number is expected. The agent can't tell "zero" from "unknown". Set a number or say so in the message.
Exercises
Exercise
An action takes a customer's postal code as input. You are choosing between a Number type and a Text type. Which do you choose, and why?
Show answer
Text. A postal code is an identifier, not a quantity. A number type removes leading zeros (for example 02134 becomes 2134) and can't hold letters or spaces, which many countries use. Describe the expected format in the input description, and validate it in the action.
Exercise
A Flow action returns the whole Order record when the customer only asked whether an order has shipped. Describe a better output design, and name one risk of the current design.
Show answer
Return one or two outputs, for example a Text Shipping Status and a Text Result Message, each with a clear description. The current design exposes every field on the record, which adds noise the agent must filter. The agent may also quote a field the customer shouldn't see or didn't ask about.