Create Custom Actions Using Apex Invocable Method

With Agentforce Builder, developers can enhance agent capabilities by creating custom actions using Apex, flows, or prompt templates. This unique extensibility empowers developers to tailor agents to their business needs. To use your Apex code in a custom action, you can annotate your method with @InvocableMethod. This annotation makes the action available for configuration in Agentforce Builder. The following sample code shows an Apex class that uses this annotation.

Sample Invocable Method
1public with sharing class HelloWorld {
2
3    @InvocableMethod(label='Hello World' description='Takes a name and returns a greeting message')
4    public static List<OutputParameters> sayHello(List<InputParameters> inputs) {
5        List<OutputParameters> outputs = new List<OutputParameters>();
6
7        for (InputParameters input : inputs) {
8            OutputParameters output = new OutputParameters();
9            output.greeting = 'Hello, ' + input.name + '!';
10            outputs.add(output);
11        }
12
13        return outputs;
14    }
15
16    public class InputParameters {
17        @InvocableVariable(required=true label='Name' description='The name of the person to greet')
18        public String name;
19    }
20
21    public class OutputParameters {
22        @InvocableVariable(label='Greeting' description='The greeting message')
23        public String greeting;
24    }
25}

To learn how to turn an invocable method into a custom action in Agentforce, review these resources.

Salesforce Help

Developer Blog

Developer Reference