Saturday, January 3, 2026

Add Apex Merge Fields to a Field Generation Prompt Template

Salesforce allows you to make AI responses smarter by using Apex merge fields in a Field Generation Prompt Template. This helps Einstein Generative AI use real-time data from your org when creating AI-generated content.

Let’s understand this with a simple example.

Business Use Case

Imagine your sales team wants to see a summary of all open cases for a customer before making a sales call. Instead of checking multiple records, Salesforce AI can automatically generate this summary and store it on the Account record.

To do this, we use:

A Field Generation Prompt Template

An Apex class to fetch open case data

Using Apex with Prompt Templates

An Apex class can be written to:

Accept an Account as input

Find all open Cases related to that Account

Prepare the case details as text

Send this text to the AI model as part of the prompt

This Apex class is exposed to Prompt Builder using the @InvocableMethod annotation. Once exposed, it can be selected as a resource inside a prompt template.

public class OpenCasesPrompt {
    @InvocableMethod(label='Open Cases'
        description='Find Cases for an Account'
        CapabilityType='PromptTemplateType://einstein_gpt__fieldCompletion')
    public static List<Response> getCasesPrompt(List<Request> requests) {
        // Validate the expected number of requests as an input
        if (requests.size() != 1)
          throw new ListException('The requests list must contain one entry only');
        Account a = requests[0].RelatedEntity;
        ID searchAcctId = a.Id;
        List<Case> cases =
            [SELECT Id, Subject, Description
             FROM Case
             WHERE AccountId = :searchAcctId AND Status != 'Closed'
             WITH USER_MODE];
        string responseData = null;
        if(cases.isEmpty()) {
            responseData = 'There are no open cases.';
        } else {
            for(Case c : cases) {  
                responseData =
                   (responseData != null) ? responseData + '\n' : '';           
                responseData += String.format('Case details: {0}, {1}.',
                    new List<Object>{c.Subject, c.Description});
            }
        }
       
        List<Response> responses = new List<Response>();
        Response res = new Response();
        res.Prompt = responseData;
        responses.add(res);
        return responses;
    }
    
    public class Request {
        @InvocableVariable(required=true)
        public Account RelatedEntity;
    }
    
    public class Response {
        @InvocableVariable
        public String Prompt;
    }
}

Key parts explained:

@InvocableMethod

Required to expose the method to Prompt Builder

label

This is the name you see in the UI (“Open Cases”)

description

Explains what the method does

CapabilityType

Tells Salesforce this method is used for Field Generation Prompt Templates

Method signature rules:

Must be static

Must accept a List of Request

Must return a List of Response

Request Inner Class (Input)

public class Request {

@InvocableVariable(required=true)

public Account RelatedEntity;

}

What this does:

Defines what input the method receives

In this case, it receives an Account record

Important points:

@InvocableVariable exposes the variable to Salesforce

RelatedEntity is automatically populated when the prompt runs

This allows the method to know which Account to process

Response Inner Class (Output)

public class Response {

@InvocableVariable

public String Prompt;

}

What this does:

Defines what data is sent back to Prompt Builder

The Prompt field holds the final text

Einstein uses this text as input context for the LLM

Creating the Field Generation Prompt Template

After the Apex class is ready, follow these steps in Prompt Builder:

Create a custom field on the Account object

Example: Open Case Summary (Text Area – Long)

Open Prompt Builder and create a new prompt template

Prompt Template Type: Field Generation

Object: Account

Object Field: Open Case Summary

Paste a sample “Summarize open cases” prompt into the workspace

Insert resources into the prompt:

Add Account ID as a merge field

Add the Apex resource that fetches open case details

The Apex class provides live case data, and Einstein Generative AI uses it to generate a clear summary.

Final Result

When the prompt runs:

Salesforce calls the Apex class

Open case details are added to the prompt

Einstein Generative AI creates a summary

The summary is saved in the Account field

This gives users up-to-date, AI-generated insights without manual effort.

Einstein Trust Layer and Its Features

As organizations begin using generative AI, trust becomes the most important factor. At Salesforce, trust is the number one value. Einstein Generative AI is built to help businesses innovate while keeping their data secure and their AI responses reliable and safe.

Your Data Stays Secure

With Einstein Generative AI, your data remains private and protected. Salesforce has strong agreements with large language model providers like OpenAI. These agreements ensure that customer data is not stored, reused, or trained on by the AI models. This allows organizations to take advantage of generative AI without worrying about data security.

Einstein Trust Layer: Designed for Trust

As Salesforce adds more generative AI features, keeping customer data safe becomes very important. The Einstein Trust Layer is built to protect data privacy, improve AI accuracy, and make sure AI is used in a responsible way across Salesforce.

The Einstein Trust Layer is a set of features, rules, and processes that work in the background whenever Einstein Generative AI is used.

How Data Flows Through the Einstein Trust Layer?

When AI is used in Salesforce, data follows a secure path:

A prompt is sent from a CRM app (like Sales or Service Cloud).

The prompt passes through the Einstein Trust Layer.

The prompt is sent to the LLM (Large Language Model).

The LLM creates a response.

The response comes back through the Einstein Trust Layer.

The final response is shown in the CRM app.

This full process helps keep data secure at every step.

Prompt Journey

To get an AI response, Salesforce sends a prompt to the LLM.

Prompts can be created using Prompt Builder and can be called from Flow or Apex.

Before the prompt reaches the LLM, the Einstein Trust Layer checks and prepares the data.

The Einstein Trust Layer Features.

Secure Data Retrieval and Grounding

For better and more accurate answers, the AI needs context from Salesforce data. This is called grounding.

Grounding means adding CRM data to the prompt, such as:

Record fields

Related lists

Flow data

Apex data

Security is always respected:

Only data that the current user has access to is used

Salesforce role and field-level security rules are followed

Grounding happens at run time, based on user permissions

This ensures users see only what they are allowed to see.

Data Masking for the LLM

To protect sensitive information, the Einstein Trust Layer uses data masking.

Sensitive data is detected in two ways:

Pattern-based detection (like emails, phone numbers, names)

Field-based detection using Salesforce data classification and Shield encryption

Once detected:

Sensitive data is replaced with placeholder text

The real data is never sent to the LLM

After the response is generated, the data is safely restored

This prevents private data from being exposed to external AI models.

Prompt Defense

To help decrease the likelihood of the LLM generating something unintended or harmful, Prompt Builder and Prompt Template Connect API use system policies. 

These policies:

Guide the LLM on how to behave

Prevent harmful or unwanted responses

Protect against prompt injection and jailbreaking attacks

Stop the AI from answering questions it does not have data for

Friday, January 2, 2026

Invoking Agentforce Agent from Record-Triggered Flows in Salesforce

Salesforce Agentforce opens up powerful new ways to bring AI-driven decision-making into your automation. One common and practical requirement is invoking an Agentforce Agent from a Record-Triggered Flow—especially for backend processes like case assignment, enrichment, or classification.

In this blog, we’ll walk through how and why to invoke an Agentforce Agent asynchronously from a record-triggered flow, along with a real-world Case Management example.

Why Invoke Agentforce from Record-Triggered Flows?

Record-Triggered Flows are widely used for:

Automating actions when records are created or updated

Enforcing business rules

Orchestrating backend processes without code

By integrating Agentforce Agents with record-triggered flows, you can:

  • Add intelligent decision logic
  • Delegate complex reasoning to agents
  • Keep flows lightweight and scalable

However, there’s an important architectural consideration.

Important Point: Agentforce Must Be Invoked Asynchronously

Agentforce Agents must be invoked asynchronously when called from a Record-Triggered Flow.

Why?

Record-triggered flows often run in before-save or after-save contexts

Agentforce execution can involve:

Reasoning

Topic evaluation

Apex actions

These operations are not suitable for synchronous execution inside record transactions

Solution

Salesforce provides an Agent Action that can be called asynchronously from the flow, ensuring:

No transaction blocking

Better performance

Compliance with platform limits

Real-World Use Case: Case Assignment Using Agentforce

Scenario

A support organization wants to automatically assign Case ownership using intelligent logic when a Case is created via the Web channel.

High-Level Flow Architecture

Case is created

Record-Triggered Flow fires (After Insert)

Flow checks condition:

Case.Origin == 'Web'

Flow invokes Agentforce Agent asynchronously

Agent evaluates a topic for case assignment

Agent calls an Apex Action

Apex assigns the Case owner based on region

Step 1: Create a Record-Triggered Flow on Case

Object: Case

Trigger: When a record is created

Run: After save

Entry Condition

Origin Equals Web

This ensures the agent is only invoked for web-created cases.

Step 2: Invoke Agentforce Agent Asynchronously from Flow

Inside the flow:

Add an Agent Action

Choose Invoke Agentforce Agent (Asynchronous)

Inputs Passed to Agent

Case Number

Case Id

Region (optional, if available on Case)

This keeps the flow simple and delegates intelligence to the agent.

Step 3: Configure Agentforce Agent

Inside Agentforce, configure an agent with a clear purpose.

Example Agent Purpose

“Assign Case owner intelligently based on Case region.”

Step 4: Create a Topic for Case Assignment

Within the Agent:

Create a Topic: Case Owner Assignment

This topic handles logic related to determining the correct owner

Topic Responsibility

Understand Case context

Step 5: Call Apex Class Action from Agent

Under the topic, configure an Apex Class Action.

Apex Action Inputs

CaseNumber (String)

What the Apex Class Does

Query the Case using Case Number

Read the Case Region

Query the appropriate Queue based on region

Assign the Queue as the Case Owner

Update the Case

Example Logic (Conceptual)

If Region = APAC → Assign APAC Support Queue

If Region = EMEA → Assign EMEA Support Queue

If Region = NA → Assign NA Support Queue

This keeps complex logic out of Flow and inside reusable Apex.

Key Takeaways

Record-Triggered Flows can invoke Agentforce Agents only asynchronously

Agentforce is ideal for complex decision-making scenarios

Combining Flow + Agentforce + Apex Actions creates a powerful automation pattern

Case assignment is a perfect real-world use case for this integration

Wednesday, December 31, 2025

How to Deploy an Agentforce Service Agent to a Salesforce Community Site

Salesforce Agentforce brings intelligent automation to your digital experiences, enabling AI-powered agents to interact with customers directly on your Experience (Community) Site. But deploying an agent isn’t just a drag-and-drop affair—it requires a series of well-orchestrated steps. Here’s your go-to guide for getting it done right.

Step-by-Step Deployment Checklist

1. Create a Service Agent

Start by creating the Agentforce agent in Salesforce. Define its topic, instructions, and actions—these determine what the agent can do and how it responds to users. Once configured, activate the agent.

2. Assign Permissions to Einstein Service Agent User

Salesforce automatically creates a Service Agent user when you create an Agentforce agent. This user needs the right permissions:

Object and field-level access to query/update records

Apex class access for custom logic

Flow access for orchestrations

Use permission sets or profiles to grant these.

3. Enable Omni-Channel

Omni-Channel is the backbone of routing in Salesforce. Enable it to allow your agent to receive and respond to incoming requests.

How to Deploy an Agentforce Service Agent to a Salesforce Community Site

4. Create Routing Configurations

Define how conversations are routed to your agent. This includes:

Routing Configurations: Set capacity and routing priority

How to Deploy an Agentforce Service Agent to a Salesforce Community Site

Fallback Queue: Ensure there's a backup if the agent is unavailable.

Under routing config select routing config.

Under supported objects select "Messaging Session". This is the object where incoming request and agent response will be recorded.

How to Deploy an Agentforce Service Agent to a Salesforce Community Site

How to Deploy an Agentforce Service Agent to a Salesforce Community Site

5. Build an Omni-Channel Flow

Create a flow that handles incoming request. With the help of this flow incoming messages are assigned to agents and agent responds back.

Before building the Omni Channel Flow. Have a look at the Connection tab on your agent which you want to put on Community.

How to Deploy an Agentforce Service Agent to a Salesforce Community Site

Flow Configuration:


Add a variable for taking input and make it available for input:


Add a Route Work element:


6. Enable Digital Experiences

Go to Setup and enable Digital Experiences to allow creation and customization of community sites.

7. Create a Community Site

Use the Experience Builder to create your site. Choose a template that supports messaging and embed the agent interface.

I am creating a Customer Service Portal.


Make sure to Activate the site from Administration.

8. Create and Activate a Messaging Channel

Set up a Messaging Channel (e.g., Web, SMS, WhatsApp) and link it to your community site. Activate it so customers can start conversations.

Under Setup > Enable Messaging Settings

Create a new Channel:






Click Save and Activate the messaging channel.

9. Create Embedded Service Deployments

Deploy the agent interface using Embedded Service Deployments. This allows the agent to appear as a chat widget on your site.


Now go to Builder and search "Embedded" as shown below and add the messaging component anywhere on the page as shown in image 1 and ensure to select "EBD_For_AF" the embedded service deployment which we just created as shown in image 2 and publish the site.


How to Deploy an Agentforce Service Agent to a Salesforce Community Site
How to Deploy an Agentforce Service Agent to a Salesforce Community Site


10. Add CORS URL

To ensure secure cross-origin communication, add your community site’s URL to the CORS whitelist in Setup.

Now, go to site and refresh the page, you will be able to see your Agentforce Agent as shown below.

How to Deploy an Agentforce Service Agent to a Salesforce Community Site

Tuesday, December 30, 2025

How to Invoke a Flow from Agentforce: A Step-by-Step Guide

Agentforce empowers Salesforce users to automate tasks and deliver intelligent responses through conversational AI. One powerful capability is invoking Salesforce Flows directly from Agentforce topics. In this article, we’ll demonstrate how to achieve this using a practical scenario: fetching Case details by Case Number.

Scenario Overview

We want our Agentforce agent to retrieve case details when a user asks for them. The agent will invoke a backend Autolaunched Flow that queries the Case object using the provided Case Number.

 Topic Details

  • Name: Get Case Details
  • Classification Description: This topic is used to get Case details by invoking a Flow in the backend using Case Number.

Step-by-Step Instructions

Instruction 1: Trigger the Topic

The topic should activate when the user asks for case details.

Instruction 2: Detect User Intent

Configure the topic to recognize phrases like:

  • “Show case details”
  • “Get details for case number 12345”
  • “Provide case information”

Instruction 3: Validate Case Number

Ensure the user provides a Case Number. If missing, prompt:

“Please provide the case number to retrieve details.”

Instruction 4: Invoke the Action

Create an Action in Agentforce:

  • Action Name: Get Case Details
  • Action Type: Flow
  • Flow: Autolaunched Flow that accepts Case Number as input
  • Pass the Case Number from the topic to the flow input variable.

Instruction 5: Handle Errors Gracefully

If the action fails, display:

“We encountered an issue while fetching case details. Please try again later.”

Instruction 6: Display Case Information

Display case information.

Action Associated to a Topic:



Flow Details:

This flow is taking  caseNumber as an input using Variable as highlighted in image

And the using get Record getting the case details and finally returning the case record to agentforce agent.

Agentforce Agent Unit Testing:

A screenshot of a conversation previewAI-generated content may be incorrect.

Note: Autolaunched don’t require manual user access i.e we do not explicitly need to give service agent access to flow.