Sub topic 3
Describing Action Inputs and Outputs
Assume you understand Salesforce objects, fields, records, and basic Flow or Apex. An action receives inputs from the agent and returns outputs that the agent can use in its response.
Describing action inputs and outputs
Describe each variable in plain language. State what the value means, where it comes from, and what the action returns.
| Variable | Description | Example |
|---|---|---|
| Input | Order number supplied by the customer | 100045 |
| Output | Current status of the order | Shipped |
| Error result | Meaning when no record matches | Not found |
Telling the agent when and how to use an action
Action instructions should specify the trigger, required inputs, and result handling.
- Ask for the order number if it is missing.
- Use Get Order Status after receiving the number.
- If the result is Not found, ask the customer to check the number.
- Otherwise, report the returned status in one sentence.
Building an invocable Apex method
An invocable Apex method exposes Apex to Flow and Agentforce as an action. Its request and response classes define the action's inputs and outputs.
public with sharing class GetOrderStatus {
public class Request {
@InvocableVariable(label='Order Number' description='Order number from the customer' required=true)
public String orderNumber;
}
public class Response {
@InvocableVariable(label='Status' description='Current status or Not found')
public String status;
}
@InvocableMethod(label='Get Order Status' description='Looks up an order status')
public static List<Response> getStatus(List<Request> requests) {
List<Response> results = new List<Response>();
for (Request request : requests) {
Response response = new Response();
List<Order> orders = [
SELECT Status FROM Order
WHERE OrderNumber = :request.orderNumber
WITH USER_MODE
LIMIT 1
];
response.status = orders.isEmpty() ? 'Not found' : orders[0].Status;
results.add(response);
}
return results;
}
}Testing and refining in Builder
Test with direct prompts, missing inputs, invalid values, and requests outside the topic. In Builder, check which topic was selected, whether the input was filled correctly, and whether the output was explained correctly. Change one description or instruction at a time, then repeat the same test.
Design practices and guardrails
Keep topics distinct so similar requests do not compete. Limit each action to the smallest necessary operation. Use user-mode queries and validate record access. Require confirmation before actions that change data, such as cancellation or updates.
Exercise
Why should an action describe both its input and its output?
Show answer
The input tells the agent what value to provide. The output tells it what result it can use and how to explain that result.