DEV Community

Hemant Jawale
Hemant Jawale

Posted on • Edited on

Supercharge Your Recruiters: Building AI-Powered Automation in Salesforce with Agentforce

Recruiting is a high-stakes, high-volume game. Your team is in a constant race to find the best candidates and fill open roles before the competition. But what if you could give them a secret weapon? What if you could infuse your Salesforce org with intelligence to automate tedious tasks and provide insightful recommendations?

That's where Agentforce comes in. By combining the power of the Salesforce platform tools and features like Flows, Prompt Builder, Apex, and Lightning Web Components (LWC) along with Agentforce, you can build powerful AI-driven tools that transform the recruitment process.

In this post, I'll walk through two practical use cases to build for your recruiting team:

1. Instant Candidate Summaries: Automatically generate concise candidate summaries directly on a record field using an uploaded resume document and the candidate details as the input.

2. AI-Powered Job Matching: Recommend the best jobs for a candidate by analyzing their uploaded resume document and matching it against open positions records in Salesforce.

I will also focus on Agentforce capabilities like Prompt Builder Templates, ModelsAPI, and the ability to orchestrate these using Apex code and Lightning Web Components to power these automations.

Ready to build? Let's get started.

You can find all the code and prompts for these examples in this GitHub Repository.
If you want a video walkthrough with a demo, give the explainer video a watch!

Use Case 1: Instant Candidate Summaries with Prompt Builder Templates

Recruiters spend countless hours reading through resumes and cover letters to distill key information. This manual process is slow and repetitive. Let's automate it using the Prompt Builder feature. Prompt Builder enables users to create and manage reusable and context-aware prompt templates that interact with a preferred Large Language Model (LLM). The best part about using Prompt Builder is that it is a low-code way to quickly build, test, and deploy these prompts; and with some basic prompt writing know-how you can quickly start building powerful AI automations in Salesforce.

For this use case, let's create a simple yet powerful automation that generates a summary of a candidate's experience and populates it into a AI summary field on the Candidate record in Salesforce. This could also be a contact or lead record depending on how and where you are capturing the candidate data.

The Goal

A recruiter should be able to trigger an action that instantly populates a "Candidate Summary" text field based on the candidate's attached resume or other relevant text fields on the Candidate detail page.

The How-To

The Prompt Builder Template allows you to create different prompt templates types depending on what you are trying to achieve. For our use case, I will use the 'Field Generation' type that is used when users click a button to run a prompt and populate a field with the AI generated output

1. Create the Prompt Template:

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 'Flex' 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 that can take a pdf/image as input. Notice how prompt templates can handle multi-modal inputs.

/* 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.
Enter fullscreen mode Exit fullscreen mode

2. The Automation:

The simplest way to trigger this prompt template is via a click of a button. You can do this by attaching the prompt template to the field on the lightning record page where you want the summary created. Follow the instuctions on this page: Add a Field Generation Prompt Template to a Lightning Record Page. Make sure you select the prompt template type that best fits your use-case.

You can test and preview the prompt response in the prompt builder using sample data from the org before activating it. Once activated, you can perform the above mentioned configuration of attaching the prompt to the candidate summary field.

Now go to any of the candidate's record detail page and click the AI generation icon next to the summary field. This calls the AI Candidate Summary Prompt Template, looks for the attached resume document, prepares the prompt, sends it to the LLM to get a response and updates the Candidate Summary field with the text. It is important to note that the Salesforce Einstein Trust Layer is an integral part of any Agentforce operation ensuring the privacy and security of your data to improve the safety and accuracy of your AI results and promoting the responsible use of AI across the Salesforce ecosystem.

3. Process Diagram for reference:

The Result

With this setup, a task that used to take 10-15 minutes is now done in seconds. That is ~ 99.6% improvement in productivity for this task!

Use Case 2: AI-Powered Job Matching

Now for a more advanced use case. How many times has a great candidate been overlooked for the perfect role simply because a human couldn't connect the dots fast enough? This AI automation solves that by intelligently matching candidates to open jobs.

The Goal

From a candidate's record, a recruiter can click a button that presents a ranked list of the best-fit jobs, complete with a "match score" and a justification for why it's a good fit.

The Architecture

For this use case to work, on the button click, we need to read the attached candidate resume file, extract their key skills, compare those skills against all open job descriptions, score and rank each match so that only the relevant results are provided.

This solution involves a few moving parts that work together seamlessly: a Lightning Web Component for the user interface, some Apex classes for the backend logic, Agentforce platform and tools like Prompt Builder and ModelsAPI.

1. The UI Display : Custom Lightning Web Component (LWC):
The Lightning Web Components (LWC) are a great way to build flexible custom UIs for Salesforce. Let's build a custom LWC that contains a simple button which when clicked, calls our Apex code to process and execute the logic and also displays the returned list of jobs, scores, and justifications in a clean, readable format.

2. Apex Class #1 to extract Candidate's Key Skills by invoking a Prompt Template

Start with an Apex Class (let's call it PromptController) that includes an @AuraEnabled method that the LWC component can call, passing the candidate's record ID.

Resume Extraction: The PromptController apex class is responsible to process our inputs and pass it to a candidate skills extractor prompt template to extract structured candidate key skills data from the unstructured resume file.

Prompt Template Invocation: In the previous use case, the prompt template was directly triggered via a button. For this use case the Apex class will invoke the Prompt Template. You can refer to the GitHub rep code; here is a help doc for reference. This prompt is specifically designed to parse the resume and return a structured list of skills.

Here's the prompt you could use:

/* Candidate Skills Extractor Prompt Template */

/* Define the role and purpose */
You are an expert AI recruiting assistant. Analyze the content of the attached resume file of the candidate. Your task is to intelligently identify all relevant professional skills, including technical skills, software proficiency, and key soft skills, and years of experience as 'X years of experience'. 

/* Define how to structure the response */
Return the skills and the years of exprience as a single, clean, comma-separated string.
Do not add any introduction, explanation, or any text other than the comma-separated list of skills.
Ignore any formatting noise from the document.

/* Ground the prompt with the candidate attached resume file */
Resume File: {!$RelatedList:CandidateProfile.CombinedAttachments.Records}
If there are multiple files, only select the file that has the word 'resume' in it's title and ignore the other files. 
Enter fullscreen mode Exit fullscreen mode

3. Apex Class #2: Match Candidate Key Skills with all Open Job Requirements with Models API

Once we have the candidate's key skills, we need to find the best open jobs for the candidate. This is where the magic happens. The extracted skills are passed to our second Apex class (let's call it BulkJobMatcher_ModelsAPI), which uses the Models API to call an LLM and perform the comparison. The ModelsAPI enables you to create such custom automations.

Create a list of all open jobs and their requirements: The job postions data would typically reside in a custom object like a Position custom object that I am using. The apex class will first query for all open jobs positions and iterate through each position to extract required skills for each and add all the open jobs and their requirements in a list.

Construct the Prompt: A prompt can be directly created in the BulkJobMatcher_ModelsAPI apex class. You can provide some instructions to the LLM for the matching logic and how you want the response format. I am instructing the LLM to create a "match score" between 0 to 100 and also asking for a brief matching justification. Once the response comes back, parse it and you can chose to filter and sort the jobs as per the match scores.

Here is an example prompt you can use in the Apex class:

/* Define the role and purpose */
You are an expert AI recruiting analyst. Your task is to compare a candidate's list of skills with a list of open jobs provided as a JSON array.

For each job in the JSON list, calculate a "match score" from 0 to 100 and provide a brief justification. Analyze the candidate's skills against the 'requiredSkills' for each job. Consider synonyms and related concepts.

/* Define how to structure the response */            
Return a valid JSON array containing an object for each job you evaluated. Each object must include the job's original 'jobId', your calculated 'score', and a 'justification'.

Output Format: You MUST return only a single, valid JSON array. Do not add any other text or comments.

/* Give a couple of example response output structures */   
Example output: [{"jobId": "a018c00000_JOB1_ID", "score": 85, "justification": "Strong match for core development skills."}, {"jobId": "a018c00000_JOB2_ID", "score": 50, "justification": "Missing key database management skills."}]

/* Ground the prompt with the candidate skills and open jobs JSON lis data */               
Candidate's Skills: candidateSkills 
JSON List of Open Jobs: jobListJson
Enter fullscreen mode Exit fullscreen mode

4. The Output
The results are displayed in a well formatted way via the LWC. I used an additional helper apex class #3 to structure the LLM response in a specific format that gets returned to the LWC. The recommended job position titles are linked to the actual position records that could be opened by the recruiter a new window.

5. Process Diagram for reference:

The Result

The recruiter now has an intelligent, data-driven list of the most promising opportunities for their candidate, complete with a score and a reason. This eliminates guesswork and ensures no great candidate slips through the cracks.

What's the ROI? Estimating Time and Cost Savings

Building this AI job-matching tool delivers significant returns by slashing the time recruiters spend on manual tasks. If you do some analysis around potential time and cost savings to understand the return on investment (ROI) of this automation, for every recruiter, this automation saves approximately 12.5 hours of work per week. Annually, that translates to a cost saving of nearly $30,000 per recruiter.

For a team of five recruiters, you're looking at over $100,000 in recaptured productivity per year.

The Qualitative ROI

The benefits of using Agentforce AI automation for recruitment aren't just financial:
Speed to Hire: By instantly identifying the best-fit roles, you can engage candidates faster, reducing the risk of losing them to competitors.

Improved Match Quality: The AI can pick up on nuanced skills and keywords that a human might miss, leading to better quality interviews and ultimately, better hires.

Enhanced Recruiter Experience: You're removing a monotonous, low-value task from your recruiters' plates. This frees them up to focus on high-value activities like building relationships with candidates, talking to hiring managers, and closing offers. This boosts morale and reduces burnout.

By investing a little time in development, you're not just building a tool; you're creating a scalable, intelligent system that delivers compounding returns in efficiency, cost savings, and hiring quality.

Conclusion

By leveraging the Salesforce platform and Agentforce AI capabilities, you can create sophisticated AI automations that have a real-world impact on your business. These two use cases barely scratch the surface. They reduce manual effort, increase efficiency, and allow your recruiters to do what they do best: build relationships and place top talent.

Future Enhancements

You can go further by adding more enhancements like drafting email replies, sending the candidate details to the hiring manager, etc. You can create and chain more AI automations to transform and automate other stages of the recruitment lifecycle. If you prefer the AI automation to happen in a more assistive fashion where you have an Agent helping the recruiter perform these tasks via a conversation, you can repurpose these prompt templates and apex classes as Agent Actions that become tasks an agent can perform as a part of their repertoire.

What other AI-powered automations are you building in Salesforce? Share your ideas in the comments below!

Top comments (0)