As a Salesforce professional, you're always looking for ways to automate processes and make your organization more efficient. But what about tasks that require a bit more... intelligence? Things like summarizing lead notes, generating personalized follow-up emails, or creating product descriptions. Doing these one-by-one is a soul-crushing time sink.
What if you could offload these tasks to an AI, and have it process thousands of records at once while you're grabbing coffee? ☕
That's not science fiction; it's the power of Prompt Template Batch Processing in Salesforce Agentforce. Today, we're going to break down what it is and build a practical example using a Flow that will save your recruiting team hours of work.
So, What's a Prompt Template Anyway?
Quick refresher: A Prompt Template is your reusable instruction manual for the AI. You build it once in Prompt Builder and tell AI exactly what you want it to do. The real magic is when you ground the data using merge fields to pull in data directly from your Salesforce records.
Think of it as a mail merge, but instead of just inserting a name, you're giving the AI context to generate something entirely new.
Why Batching is a Game-Changer 🚀
Okay, so you have a cool prompt. Running it on one record is neat. But running it on 10,000 records asynchronously is where you unlock serious power. Batching is a big deal because:
✅ It's Massively Efficient: Forget running things one by one. Process huge volumes of records in the background without tying up system resources. Batch Processing handles queueing, batching, and execution of jobs in the background, making it ideal for high volume use cases where real-time response is not required.
📈 Scale: Got a massive data cleanup or enrichment project? Batch processing is built to handle enterprise-level data volumes without breaking a sweat. It can handle large-scale generation of prompt responses across hundreds or thousands of input records.
💰 It's Cost-Effective: More efficiency means a better bang for your buck on AI usage. Batch Processing is recommended for helping large requests avoid hitting the large language model (LLM) rate limit.
😴 Asynchronous Processing: Schedule your jobs to run overnight or daily. The system does the work while you sleep.
Let's Build! Automating Candidate Summaries with Batch Prompts via Flows ⚡️
You can also review a video walkthough of the whole process!
The Scenario
We have new Candidate records coming in everyday. Our recruiters are spending too much time reading through the uploaded resume and the walls of text in the various fields.
We have a custom object called Candidate with fields for the candidate details like Name, experience, skills, etc. We also have a Summary field called Candidate AI Summary field (a long text area) where we want to store the AI-generated summary.
Our goal is to automate this process such that everyday, we find all candidate records that haven't been summarized and then generate and save a summary for each one.
We're going to build a schedule-triggered Flow that runs daily, finds all candidate records that haven't been summarized, and then uses a prompt template to generate a crisp and concise summary for every new candidate on a Candidate AI Summary field on each candidate's record.
1. Create the prompt template in Prompt Builder:
First, you'll create a prompt template in Salesforce's Prompt Builder. This template will take the candidate's attached resume document along with any candidate record field information as input and instruct the LLM to generate a summary. I chose the 'Field Generation' prompt template type since that best fit for what I am trying to achieve.
Here are the prompt instructions. It's designed to be clear and specific, ensuring the LLM returns a well-structured summary. Make sure to select the appropriate LLM model that can take a pdf/image as input. Notice how this prompt template takes the attached documents as input.
/* Candidate AI Summary Prompt Template */
/* Define the role and purpose */
Your job as a recruiter assistant is to extract and summarize a candidate’s profile that gets stored on a summary field.
/* Define how to structure the summary */
Use the details below to summarize the candidate's professional background in this format:
Candidate Name:
Candidate Overview: (Also include information like location, linkedin link if provided)
Key Skills Highlights:
Total Years of Experience in [field of expertise. e.g engineering]:
Most recent job title with the years or experience in that role:
Key accomplishments: (less than 4 bullet points)
Relevant certifications: (only show if there are certifications)
/* Ground the prompt with the candidate details data in Salesforce */
Candidate: {!$RecordSnapshot:Candidate__c.Snapshot}
Resume: {!$RelatedList:Candidate__c.CombinedAttachments.Records}
Name: {!$Input:Candidate__c.First_Name__c} {!$Input:Candidate__c.Last_Name__c}
Education: {!$Input:Candidate__c.Education__c}
Location: {!$Input:Candidate__c.City__c}, {!$Input:Candidate__c.State_Province__c}, {!$Input:Candidate__c.Country__c}
Interested Domains: {!$Input:Candidate__c.Interested_Domains__c}
/* Add instructions on how you prefer to handle the output response and format and style */
Format the output as a rich text structured candidate profile summary in clear and easy-to-read points and bullet points when needed. Include deep links to their linkedin profile and other sources like Github or portfolios ONLY if they are in the resume. Do not add any extra formatting characters like * or **
Don't add any pleasantries at the end of the summary.
2. Configure a Schedule-Triggered Flow
Salesforce Flow is a powerful, no-code tool within the Salesforce platform that automates complex business processes and also helps creates user interfaces by connecting different Salesforce elements using a drag-and-drop interface. You can trigger a prompt template via flows using prompt template flow actions.
A schedule-triggered flow runs in the background at a specified time and at a repeated frequency (daily, weekly, or once) to perform actions on a batch of records. Schedule-triggered flows can save time and minimize manual data update risk by automating these updates. You can schedule flows to run in off-hours to minimize potential record conflicts with users. A schedule-triggered flow runs independent of a record change.
From the Setup, create a new flow and select the Schedule-Triggered Flow option.
We'll set it to run daily and select our Candidate object. You can always filter for which candidate records you want the flow to run against, but in my case I am running it for all records.
We will start with the Decision element to check if the candidate record already has a summary saved. In the outcomes, I have created a No outcome to check if the Candidate AI Summary field is Blank. You can rename the default outcome to Yes which means we do not need to further process the records that already have a summary.
On the No outcome branch, add an Action element and look for the Candidate AI Summary (Batch Generation) prompt template action
Give it a label and set timeout length to 1 Days. Set the input value to the triggering candidate record.
Now, on the completed branch, we'll use an Update Records element to update the Candidate AI Summary field of the current candidate record with the prompt response output from the prompt template action.
The final flow should looks like this:
3. Automation in Action
Once the Flow is saved and activated, it will run every day at the scheduled time. Keep in mind that the execution is asynchronous. The actual time to complete depends on the model provider and may vary. Batch Generation supports up to 1,000 generations in approximately 24 hours. In my testing, the jobs generally start executing 2 hours after the scheduled time and the 1 day timeout length works well.
Once the flow is triggered, an AiJobRun
is created with the Ready
status. The job has several job items for each records and once the job begins processing, the status updates to InProgress
, some AiJobRunItem
fields become immutable. Once the job completes, it updates to Completed
status for successful and Failed
for error runs.
You can review the status of the AiJobRun
and AiJobRunItem
by using a tool like the Bench Press Extension for Salesforce or Postman or cURL commands.
Recruiters can now see these summaries generated and saved on the candidate record pags for all the new candidates, thus saving a lot of time and effort.
Conclusion
Prompt Template Batch Processing in Agentforce is a powerful tool for automating AI-powered tasks in Salesforce. By combining the reusability of prompt templates with the efficiency of batch processing via flows, you can create sophisticated automations that save time, reduce manual effort, and unlock new levels of productivity.
The example we walked through is just the beginning. You can use this same approach to automate a wide range of tasks, from generating product descriptions to summarizing case notes. You can also batch process prompt templates using Apex instead of Flows. So, what will you automate next?
Top comments (2)
Thanks Hemant for this article, it was really helpful. Can you also help me understand how can we break down the response and update the values in multiple fields.
Thank you Shravan.
One way to do that would be to assign the prompt response to an Apex-Defined Data Type variable in flow.
You can also chose to have the Prompt Template response as a JSON instead of the default text format. You can chose the output response type in a Flex type prompt template.
The other would be, instead of using flows, you batch run and manage it from Apex directly to have more control on the outpur response formatting.