Sub topic 2
Required Inputs and Asking the User
Assume you know Salesforce Setup, Agentforce Builder, and basic Flow or Apex. You should also understand that a large language model chooses actions from their metadata.
Required inputs and user questions
Mark an input as required when the action cannot produce a useful result without it. Describe what the value means, where it comes from, and what the agent should do when it is missing.
For example, an order lookup needs an order number. The description should tell the agent to ask the customer for that number. It should also tell the agent not to invent one.
public class Request {
@InvocableVariable(
label='Order Number'
description='Order number provided by the customer, such as 00000101. Ask for it if missing. Do not guess.'
required=true
)
public String orderNumber;
}A required input does not automatically create a good conversation. The description gives the agent guidance about when and how to collect the value.
Choosing data types and structure
Choose the simplest type that represents the value accurately. Use a text value for identifiers that may contain leading zeros. Do not use a number for an order number such as 00000101, because numeric conversion can remove those zeros.
Use a separate field for each value the action needs. Avoid one large text field that combines several values. Clear structure makes the input easier for the agent to populate.
Designing outputs the agent can explain
Return only the information needed for the agent's response. Give each output a clear label and description. Include a plain-language message for both success and empty-result cases.
public class Response {
@InvocableVariable(
label='Order Status'
description='Current status, such as Draft or Activated. Empty when no order matches.'
)
public String status;
@InvocableVariable(
label='Result Message'
description='Short message explaining whether an order was found.'
)
public String message;
}Controlling what the agent and user see
An output can help the agent reason without needing to appear in the conversation. Keep internal identifiers, query details, and diagnostic values hidden unless the customer needs them. Expose customer-safe fields such as status and result message.
Exercise
Should an order number be a numeric input when leading zeros are meaningful?
Show answer
No. Use a text input so the agent preserves the exact value the customer provided.