How do you write an Apex @InvocableMethod correctly for use as an Agentforce Action?
Suggested answer
Key requirements for Agentforce-compatible @InvocableMethod:
1. List parameters: The method must accept a single List<YourRequestClass> parameter and return List<YourResponseClass> (or List<String> for simple outputs). This is a hard Salesforce platform requirement.
2. label annotation: @InvocableMethod(label='Get Account Details') — this is what appears in Agent Builder as the action name. Make it clear and action-oriented.
3. description annotation: description='Retrieves the account name, ARR, and primary contact for a given Account ID.' — this description is passed to the LLM Planner and is critical for correct action selection. Be specific about inputs and outputs.
4. @InvocableVariable: Each field in the request/response inner classes should be annotated with @InvocableVariable(label='...' description='...' required=true/false). The description helps the LLM correctly populate the input variable from the conversation context.
5. Bulkification: Although agents typically call with one record at a time, always handle the list correctly in case of bulk invocation via other callers.
Practice content for interview preparation; not an official vendor answer. Verify details against current product documentation.
Community comments (0)
No comments yet.
Sign in or create a free account to add a comment. Comments are moderated before they appear.