Mastering Salesforce Prompt Builder: How to Securely Invoke Apex for Dynamic Data Grounding?
Dec 1, 2025
Show More Show Less
View Video Transcript
0:07
Hello everyone. In this video, we are
0:09
going to see how to make use of
0:12
Salesforce Apex in the prompt template.
0:16
With the help of Apex, we can
0:19
dynamically
0:22
add more context to the prompt that will
0:25
be sent to the large language models.
0:29
In Salesforce prompt template, we will
0:32
be able to select the Apex uh class so
0:36
that the Apex class and the method will
0:38
be executed. The written information
0:41
from the Salesforce Apex will be passed
0:45
along with the other prompt information.
0:48
It will be dynamically passed to the
0:51
large language models so that the
0:53
response written by the large language
0:56
models will be accurate and we can also
1:00
try to avoid hallucinations when using
1:04
prompt templates. Let's look at this uh
1:07
simple uh Apex class.
1:16
Using this account summary service Apex
1:19
class, I'm using
1:22
two inner classes request and response.
1:26
In the request, I'm looking for account
1:30
object. The API name is or the variable
1:34
name is input account. When I created
1:37
this uh flex prompt template, I made
1:41
sure
1:43
the
1:46
the the inputs for this prompt template
1:49
will have input account as the label and
1:51
the input account as the API name.
1:55
So when I created the prompt template
1:59
we can add
2:02
up to five inputs and it is optional.
2:07
I have select I have given the name as
2:09
input account. API name as input account
2:12
source type is object and for the object
2:15
selection I have selected account
2:17
object. I have enabled require when
2:21
template runs so that the prompt
2:23
template shouldn't run without this
2:25
input
2:27
and uh this is the pro this is the
2:30
prompt template I have used in the
2:34
prompt instruction I have given please
2:35
analyze the activity list provided below
2:38
for this account categorize and
2:41
summarize the activities into two
2:43
distinct sections one completed
2:46
activities summarize what has been done.
2:49
Highlighting key highlighting key
2:51
outcomes or decisions made. The second
2:54
one is pending or upcoming activities.
2:57
List outstanding tasks next steps and
3:01
any associated due dates for these
3:04
tasks. Keep the summary concise and
3:07
professional.
3:08
And for the and and for dynamically
3:11
passing the list of um accounts sorry
3:15
list of tasks I'm making use of account
3:18
summary apex class.
3:22
So in this apex class I'm making use of
3:25
get recent activity method. In this
3:28
method I'm getting the account that is
3:31
passed. using the account ID I'm getting
3:34
the um five recent activities that is
3:38
task for this particular account and
3:41
then I am passing subject
3:44
status and activity due date for this uh
3:49
for all the tasks that are related to
3:52
this account. So I'm I'm getting the
3:54
five tasks. I'm um uh getting the
3:57
subject status and activity u date and
3:59
then I'm passing it back to the uh
4:02
prompt template. So when this prompt
4:05
template runs, it will fetch the
4:09
account tasks that that are five account
4:11
tasks and it will merge the existing
4:14
instructions and then it will be sent to
4:16
the large language models and that will
4:20
give the response back to me. So this is
4:22
the response I am able to get it from
4:25
the LLM.
4:34
Please check the video description. In
4:36
the video description, I have given my
4:37
blog post. From the blog post, you
4:40
should be able to get the sample Apex
4:42
class and also the sample prompt
4:45
instruction that was used in this video
4:48
as a reference.
4:55
I hope it was helpful.
5:02
Thank you for watching.
#Internet Software
