With the rise of AI-powered experiences across all the things , businesses are looking for smarter ways to interact with data, automate decisions, and enhance user workflows. Enter Salesforce Prompt Builder — a no-code/low-code tool that brings the power of generative AI directly into your Salesforce org.
Simplify your users’ daily tasks by integrating generative-AI moments powered by prompt templates into their workflow. Create, test, revise, customize, and manage prompt templates that incorporate your CRM data from merge fields that reference record fields, flows, related lists, and Apex. Prompt Builder helps you to make effective prompts that safely connect you and your data with LLMs.
In this blog, we’ll explore a practical use case where Prompt Builder helps extract and analyze text from uploaded files, showcasing how easy it is to build and integrate AI into your existing Salesforce workflows.
Table of Contents
ToggleScenario: Document Validation with AI
In this guide, we’ll walk through how to extract and analyze text from uploaded files (like Aadhaar or PAN cards) and automatically verify if they are valid documents using Salesforce Prompt Builder. The process also involves writing Apex to handle prompt invocation and integrating the logic into a Screen Flow for seamless automation.
Here is the step by step process for this-
Step 1: Create a Prompt Template
- Navigate to Prompt Builder in Salesforce Setup.
- Click on “New Prompt Template”.
- In the Prompt Template Type, select Flex.
- Provide the following:
- Prompt Template Name: Document Checker
- Description: Document Checker
Click Next.
Step 2: Define Resource for File Input
On the Resources screen:
- Click “Add Resource”.
- Fill in:
- Name: Document
- API Name: Document
- Source Type: Object
- Object: Choose the object where files are uploaded (e.g. object).
Click Next.
Step 3: Write the Prompt
In the Prompt Template Workspace:
Write a prompt that asks the AI to verify the uploaded document.
Example prompt:
You are a VRL Documents checker reviewing the account: {!$Input:document__c.Name}
You have received a set of images related to this account from the following source:{!$RelatedList:document__c.CombinedAttachments.Records} These images may include documents such as the PAN card and Aadhaar card.
Your task:
Carefully review all attached files and images.
Examine the content of each file in detail, including:
PAN card details (e.g., PAN number, name, date of birth)
Aadhaar card details (e.g., Aadhaar number, name, address)
Evaluation Criteria:
Aadhaar Card:
Check if the Aadhaar card is present.
If not found, state: Aadhaar Card – ❌ Not Found
If found, validate that the Aadhaar number is exactly 12 digits.
If valid, state: Aadhaar Card – ✅ Valid
If invalid, state: Aadhaar Card – ❌ Invalid
PAN Card:
Check if the PAN card is present.
If not found, state: PAN Card – ❌ Not Found
If found, validate that the PAN number follows the format: 5 uppercase letters, 4 digits, and 1 uppercase letter (e.g., ABCDE1234F).
If valid, state: PAN Card – ✅ Valid
If invalid, state: PAN Card – ❌ Invalid
Response Format:
Only respond using the following format. Do not provide summaries, explanations, or additional text.
Aadhaar Card – ✅ Valid | ❌ Invalid | ❌ Not Found
PAN Card – ✅ Valid | ❌ Invalid | ❌ Not Found
- From the side panel, select the appropriate model (e.g.Vertex AI Gemini 2.0 Flash 001).
Click Save & Preview to test your prompt with sample file data.
If the file has an image attached, it will also preview the image.
Step 4: Create Apex Class to Call the Prompt
You can call the prompt directly from Flow, but if the logic is complex or you deal with large files, you may hit CPU time exceeded errors. So it’s better to use Apex.
public with sharing class PromptInvoker {
public class InputWrapper {
@InvocableVariable(required=true)
public Id recordId;
}
@InvocableMethod(label='Generate Prompt Responses ')
public static List<String> getPDDPromptResponses(List<InputWrapper> inputs) {
List<String> result = new List<String>();
if (inputs == null || inputs.isEmpty()) {
return result;
}
Id quotationId;
if(inputs.size()>0 && inputs[0] != null){
quotationId = inputs[0].recordId;
}
String responseString = '';
for (Documents__c doc : [
SELECT Id, Name
FROM Documents__c
WHERE Quotation__c = :quotationId ]) {
Map<String, String> experienceSession = new Map<String, String>();
experienceSession.put('id', doc.Id);
ConnectApi.WrappedValue experienceSessionValue = new ConnectApi.WrappedValue();
experienceSessionValue.value = experienceSession;
Map<String, ConnectApi.WrappedValue> inputParams = new Map<String, ConnectApi.WrappedValue>();
inputParams.put('Input:DOC', experienceSessionValue);
// Configure invocation parameters
ConnectApi.EinsteinPromptTemplateGenerationsInput executeTemplateInput = new ConnectApi.EinsteinPromptTemplateGenerationsInput();
executeTemplateInput.additionalConfig = new ConnectApi.EinsteinLlmAdditionalConfigInput();
executeTemplateInput.additionalConfig.applicationName = 'PromptBuilderPreview';
executeTemplateInput.isPreview = false;
executeTemplateInput.inputParams = inputParams;
try {
// Call the service
ConnectApi.EinsteinPromptTemplateGenerationsRepresentation generationsOutput = ConnectApi.EinsteinLLM.generateMessagesForPromptTemplate(
'Document__Checker',
executeTemplateInput
);
ConnectApi.EinsteinLLMGenerationItemOutput response = generationsOutput.generations[0];
String promptResult = response.text;
if (String.isNotBlank(promptResult)) {
responseString += doc.Name + ' : ' + promptResult + '\n';
}
} catch (Exception e) {
System.debug(e.getMessage());
throw e;
}
}
if (responseString.endsWith('\n')) {
responseString = responseString.removeEnd('\n');
}
result.add(responseString);
System.debug(result);
return result;
}
}
Step 5: Use Apex in a Screen Flow
- Create a Screen Flow.
- Add an Apex Action element.
- Search for your class: PromptInvoker .
- Pass the uploaded record ID as input.
- Store the AI response in a Text variable.
- Display this Prompt Builder response using a Screen element in the flow.
Activate the flow and embed it in your record page layout .
Conclusion
Now, whenever a file (image or PDF) is uploaded:
- The Prompt Builder reads the file,
- Extracts and analyzes the content,
- Determines if it’s a valid Aadhaar, PAN, or other government document,
- Returns the result to the user in a flow screen or stores it on the record.
You can also check out our YouTube videos on Prompt Builder for a better understanding
You can deepen your understanding of Data Cloud by exploring our comprehensive course on Salesforce Data Cloud and Agentforce – Building Agents and also check out our latest blogs on our websites for additional knowledge about salesforce.