Invoke Salesforce Agentforce from Apex
3K views
Feb 7, 2025
Invocable.Action.createCustomAction( 'generateAiAgentResponse', 'Agentforce Agent API Name' ) can be used to invoke Salesforce Agentforce Agent from Apex. Blog Post: https://www.infallibletechie.com/2025/02/invoke-salesforce-agentforce-from-apex.html
View Video Transcript
0:05
hello everyone in this video we are
0:08
going to see how to invoke
0:11
Salesforce agent force agent from
0:18
Apex using invocable doaction do create
0:22
custom action we have to pass generate
0:25
AA agent
0:27
response and we have to to pass the API
0:31
name of the agent force
0:34
agent once we pass these two
0:37
information to this uh invocable
0:41
invocable doaction do create custom
0:43
action method we will be able to invoke
0:47
Salesforce agent force agent from
0:49
Apex let's look at this
0:52
example here I have a method a class
0:56
called agent force request Handler I'm
0:59
using a static method called summarize
1:02
opportunity from agent
1:05
force the variable opportunity
1:08
name will contain the opportunity name
1:11
so you can pass the opportunity name to
1:13
it using invocable do
1:17
action do create custom action I am
1:20
passing generate a agent response comma
1:24
the API name of the agent force agent so
1:28
here the API name of the agent force
1:32
agent is copilot uncore foror Salesforce
1:36
so I have passed that information you
1:39
can pass multiple input parameters as of
1:42
now I'm passing the standard user
1:44
message which is a prompt so here I'm
1:48
sending user message as summarize my
1:52
opportunity space the opportunity
1:56
name it will call the invoke method
2:00
from the result I'm getting the first
2:02
result if it a
2:04
success I am getting the session ID and
2:07
then I'm displaying it using system.
2:09
debug
2:11
statement using another system. debug
2:14
statement I'm getting the agent respond
2:18
response if there were any
2:20
errors it will uh add the error in the
2:24
system. debug
2:26
statement let's execute this I have an
2:29
opportunity
2:31
with the with the name testing
2:33
opportunity so I'm going to pass the
2:35
opportunity name to this class and
2:38
Method so that it will call the agent
2:41
force agent and then it will get the
2:43
response from the agent force agent so
2:46
let's execute
2:50
it so now the Apex is calling this class
2:53
and method which in turn will execute
2:55
the agent force agent
3:11
so I got the opportunity
3:16
summary from the agent force
3:20
agent if you do the same here
3:38
since I'm using single record summary
3:40
standard Salesforce topic it will
3:43
summarize my opportunity and then it
3:45
will return the response same thing I
3:47
was able to achieve it using Salesforce
3:57
Apex please check the video description
4:00
in the video description I have shared
4:01
my blog post from the blog post you
4:03
should be able to get the sample Apex
4:06
code for your
4:14
reference I hope it was
4:21
helpful thank you for
4:28
watching for
#Internet Software