Blog Post:
https://www.infallibletechie.com/2026/02/invoke-salesforce-prompt-template-from-lwc-using-apex.html
Show More Show Less View Video Transcript
0:07
Hello everyone. In this video, we are
0:10
going to see how to invoke Salesforce
0:13
prompt template from Salesforce
0:16
Lightning web component. As of now we
0:19
don't have a library
0:22
like what we have for get record element
0:24
uh record or uh using lightning
0:28
navigation like that we have several
0:30
libraries in Salesforce lightning web
0:33
component which can be used but in order
0:36
to invoke light um the prompt template
0:39
from the lightning web component
0:40
currently we don't have an option or the
0:43
library option
0:45
but if you have a an use case where you
0:48
wanted to invoke the Salesforce prompt
0:51
template from the lightning web
0:53
component then we can call Salesforce
0:57
apex class from the lightning web
1:00
component using connect API we can
1:02
invoke the prompt template in Salesforce
1:05
apex and then we can send the response
1:08
back to the lightning web component and
1:10
then we will be able to display it.
1:14
So the architecture is from the
1:16
lightning web component apex will be
1:18
invoked in apex the prompt template will
1:21
be uh invoked and the response from the
1:24
prompt template will be sent back to
1:26
apex and from the apex it will be sent
1:28
back to lightning web component and then
1:30
it will be displayed.
1:32
Let's see uh
1:35
um a prompt template. In this prompt
1:37
template, I'm going to get the input
1:40
from the user and then I'm going to
1:43
refer agent force data library and then
1:47
I'm going to send the content back to
1:50
the user based on the input whatever
1:52
they have um given here. I'm making use
1:57
of a retriever called fi file library.
2:02
Let's go to setup.
2:06
If I go to agent force data library,
2:10
I have set up multiple libraries but we
2:13
are going to see the file library.
2:19
So this is the file library.
2:23
Here I have added multiple uh files and
2:27
I'm going to get the response back from
2:29
the user sorry from the file and then
2:31
I'm going to give the response back to
2:33
the user.
2:35
So this is the
2:37
files data source
2:40
agent force data library. Let's test it
2:43
out. This is my lightning web component.
2:46
I'm going to ask how to change the asset
2:50
location.
2:54
So now it is invoking the apex class.
2:56
The apex class is calling the prompt
2:58
template.
3:00
Once the prompt template is invoked, it
3:02
will get the response back and then it
3:04
will be displayed back in the lightning
3:06
web component.
3:09
This information I'm able to get it from
3:12
the files that were that were uploaded
3:15
in the agent force data library.
3:20
So this is a apex class where I'm making
3:24
use of connect API to invoke the prompt
3:27
template.
3:29
So the prompt template uh API name is
3:31
knowledge base.
3:37
I have given my apex class and the
3:39
lightning web component code which were
3:41
used in this video for your reference.
3:48
In the targets I have given app page,
3:51
homepage, record page and uh community
3:53
pages.
3:55
As of now there is a known issue from
3:57
Salesforce platform which is not
4:00
allowing uh so that the external users
4:03
can invoke
4:05
uh the prompt template from Salesforce
4:08
Apex. Once that known issue is fixed,
4:10
you should be able to give this
4:13
lightning web component access to the
4:15
external users, the Salesforce
4:17
experience cloud users so that they can
4:19
also make use of this lightning web
4:22
component which will invoke Apex and
4:25
from Apex it will invoke the prompt
4:27
template.
4:34
Please check the video description. In
4:36
the video description, I have given my
4:38
blog post which can be used for your
4:40
reference.
4:50
I hope it was helpful.
5:00
Thank you for watching.
#Internet Software
