Sunday, October 12, 2025

Automating Account & Contact Creation using Agentforce Agent And Using Apex As An Action

Use Case Overview:

Let’s say a customer initiates a chat or call, and the agent (or bot) collects basic details like company name, contact name, and email. Instead of manually creating records or building complex Flow logic, you can invoke a single Apex method from the Agentforce Topic to:

  • Check if the Account already exists

  • Create the Account if needed

  • Create a related Contact

  • Return success or error messages to the agent or bot

Pre-requisite:

Turn On Einstein Setup
Enable Einstein for Sales
Assign below Permission Sets to your user

Prompt Template Manager – for users who create and manage templates

Prompt Template User – for users who run the templates




Let's create a Agentforce Agent now.

Automating Account & Contact Creation using Agentforce Agent And Using Apex As An Action

In next step, un select all selected topics.

Automating Account & Contact Creation using Agentforce Agent And Using Apex As An Action


Automating Account & Contact Creation using Agentforce Agent And Using Apex As An Action

We are not specifying any data source. Click create.

Create a Topic in next step as shown below along with Instructions properly specified and attached an apex action to the Topic.

Name: AccountContactCreationTopic

Classic Description: The AccountContactCreationTopic facilitates real-time creation of Account and Contact records in Salesforce by invoking the AccountContactCreator Apex class.

Scope: Your job is to create Account Contact only

Instructions:

Instruction 1:

Select this topic when the user says or implies any of the following:

“I want to create an account and contact”

“Add a new company and person”

“Register a new customer”

“Create contact for this account”

“Set up a new business record”

This topic should be triggered by bot intent, agent selection, or guided flow when the goal is to create both an Account and a related Contact in Salesforce.

Instruction 2:

Below variables must be collected before invoking the Apex class:

Variable Name Required Description Validation Tip
accountName Yes Name of the Account (company/org) Must not be blank
contactFirstName Yes First name of the Contact Must not be blank
contactLastName Yes Last name of the Contact Must not be blank

Instruction 3:

Optional variables (recommended if available):

Variable Name Required Description
accountPhone No Phone number of the Account
accountWebsite No Website of the Account
contactEmail No Email address of the Contact
contactPhone No Phone number of the Contact

Instruction 4:

Call the action AccountContactCreator for creating account and contact

Instruction 5:

Once the action is successfully executed display the message The Account and Contact have been created successfully. Account ID: {accountId}  andContact ID: {contactId}

Automating Account & Contact Creation using Agentforce Agent And Using Apex As An Action

Action associated to a Topic:


Agentforce Service Agent
Agentforce Service Agent

Agentforce Service Agent
Agentforce Service Agent

Agentforce Service Agent


Apex Class:

public class AccountContactCreator {

    public class AccountContactInput {
        @InvocableVariable(required=true)
        public String accountName;

        @InvocableVariable
        public String accountPhone;

        @InvocableVariable
        public String accountWebsite;

        @InvocableVariable(required=true)
        public String contactFirstName;

        @InvocableVariable(required=true)
        public String contactLastName;

        @InvocableVariable
        public String contactEmail;

        @InvocableVariable
        public String contactPhone;
    }

    public class AccountContactOutput {
        @InvocableVariable
        public String resultMessage;

        @InvocableVariable
        public Id accountId;

        @InvocableVariable
        public Id contactId;
    }

    @InvocableMethod(label='Create Account and Contact' description='Creates Account and associated Contact records')
    public static List<AccountContactOutput> createAccountContact(List<AccountContactInput> inputList) {
        List<AccountContactOutput> results = new List<AccountContactOutput>();

        for (AccountContactInput input : inputList) {
            AccountContactOutput output = new AccountContactOutput();

            try {
                // Check if Account already exists
                List<Account> existingAccount = [SELECT Id FROM Account WHERE Name = :input.accountName LIMIT 1];

                Account account;
                if (existingAccount.size() > 0) {
                    account = existingAccount[0];
                } else {
                    account = new Account(
                        Name = input.accountName,
                        Phone = input.accountPhone,
                        Website = input.accountWebsite
                    );
                    insert account;
                }

                Contact contact = new Contact(
                    FirstName = input.contactFirstName,
                    LastName = input.contactLastName,
                    Email = input.contactEmail,
                    Phone = input.contactPhone,
                    AccountId = account.Id
                );
                insert contact;

                output.resultMessage = 'Account and Contact created successfully.';
                output.accountId = account.Id;
                output.contactId = contact.Id;

            } catch (Exception ex) {
                output.resultMessage = 'Error creating Account/Contact: ' + ex.getMessage();
            }

            results.add(output);
        }

        return results;
    }
}


Now, it is time to Test. Before testing make sure you create a permission set and enable access to Apex Class created above and asssign it to agent associated to your service agent.

Agentforce Service Agent

Saturday, October 4, 2025

How to Create a record summary Prompt Template in Salesforce?

To create a Record Summary Prompt Template in Salesforce, use Prompt Builder to write a short summary of a record (like an Account or Opportunity) using AI. It helps users quickly understand key details without reading every field.

Here’s a simple step-by-step guide:

Steps to Create a Record Summary Prompt Template

Open Prompt Builder

In Setup, search for Prompt Builder.

Click Prompt Builder → Then click New Prompt Template.

Choose Template Type

Select Record Summary as the template type.

Enter Basic Info

Give your template a Name and Description.

Example:

Name: Case Record Summary Template

Description: This template is used to summarize case record details

How to Create a record summary Prompt Template in Salesforce?

In the next step, add prompt and select one existing record to preview and finally activate the template.

How to Create a record summary Prompt Template in Salesforce?

Now, let's design a screen flow as shown below.

Image 1:

How to Create a record summary Prompt Template in Salesforce?


Image 2: 

How to Create a record summary Prompt Template in Salesforce?

Image 3:

Case Summary Screen:

How to Create a record summary Prompt Template in Salesforce?

Display Element inside Case Summary Screen:

How to Create a record summary Prompt Template in Salesforce?

To use this flow  on a Lightning record page, add this component to lightning record page under Lightning App Builder for Case object as shown below.

How to Create a record summary Prompt Template in Salesforce?

Now, it is time to see the changes in action, open case and view the results as shown below.

How to Create a record summary Prompt Template in Salesforce?

Friday, October 3, 2025

How to Create a Field Generation Prompt Template in Salesforce?

Salesforce now lets you use generative AI to automatically fill in fields on Lightning record pages. This feature is called a Field Generation Prompt Template, and it helps users quickly add summaries or descriptions using AI. It’s a great way to make customer conversations more productive and save time on manual writing.

Let’s walk through how to set it up in simple steps.

Steps to Create a Field Generation Prompt Template

Go to Prompt Builder

In Setup, search for Prompt Builder in the Quick Find box.

Click on Prompt Builder.

Click New Prompt Template.

In the dropdown, choose Field Generation as the template type.

Fill in Basic Details

Give your template a name.

Choose the Object that contains the field you want AI to fill (like Account, Case, etc.).

How to Create a Field Generation Prompt Template in Salesforce?


In the next step, add prompt and select one existing record to preview and finally activate the template.

How to Create a Field Generation Prompt Template in Salesforce?


To use this template on a description field on a Lightning record page, Dynamic Forms must be enabled. Enable Dynamic Forms for case object in lightning record page under Lightning App Builder.

Note: Not all objects support Dynamic Forms. Check Salesforce’s list of supported objects.

Now, Choose the Field "Description" in our case and select the prompt template we created just now as shown below.

How to Create a Field Generation Prompt Template in Salesforce?

Save and Activate the lightning record form. 

Now, open one case and you will be able to see the icon Sparkle icon  appears on description field as shown below. If you click on icon you will be able to see Einstein in action as shown in second image and the text generated can be used after clicking use button. The text will be added to description field automatically and can be save on case.

How to Create a Field Generation Prompt Template in Salesforce?


Thursday, October 2, 2025

What Is Salesforce Prompt Builder and How to Enable It?

Salesforce is rapidly evolving with AI-powered features, and one of the most exciting additions is Prompt Builder. Designed to empower admins and developers, Prompt Builder turns you into a prompt engineer without needing to write code. But what exactly is it, and how do you enable it in your org? Let’s dive in.

What Is Salesforce Prompt Builder?

Prompt Builder is one of its most powerful tools. It allows admins and developers to create intelligent, data-driven prompts that communicate directly with large language models (LLMs) like ChatGPT. Whether you're automating service responses or generating sales emails, Prompt Builder puts generative AI at your fingertips.

Why It Matters?

No-code AI integration: Admins can build prompts without writing code.

Data-aware outputs: Prompts can include merge fields from Salesforce records.

Reusable templates: Create once, use across flows, Apex, or screen components.

Preview and test: Simulate outputs before deploying to users.

What Is a Prompt Template in Salesforce?

A Prompt Template in Salesforce is a reusable, structured instruction that guides a large language model (LLM) to generate intelligent, context-aware responses using real-time Salesforce data.

How It Works?

Prompt Templates use merge fields to dynamically pull data from Salesforce records. These fields are written in a special syntax like:

{!$Input:Sender.Name}

{!$Input:Recipient.MailingCity}

Here is one example:

Case Summary for Support Agent

Case {!$Input:Case.CaseNumber} was opened by {!$Input:Contact.Name} regarding {!$Input:Case.Subject}. The customer is located in {!$Input:Contact.MailingCity} and uses {!$Input:Product.Name}. Previous interactions include {!$Input:Case.PreviousComments}. Recommend next steps based on similar resolved cases.

When this runs, Salesforce fills in the blanks with actual data—so the AI knows exactly who’s speaking, who they’re speaking to, and what context to use.

How to Get Started with Salesforce Prompt Builder?

Before you can start building intelligent prompt templates, you need to enable the right Einstein features and assign permissions. Here's a quick 3-step guide to get you up and running:

Turn On Einstein Setup

Go to Setup and search for Einstein Setup. This activates the foundational AI capabilities across your org.

What Is Salesforce Prompt Builder and How to Enable It?

Enable Einstein for Sales

Still in Setup, search for Einstein for Sales and enable it. This unlocks generative AI features like Prompt Builder, Sales Emails, and AI-powered recommendations.

What Is Salesforce Prompt Builder and How to Enable It?

Assign Permission Sets

To access and use Prompt Builder, assign the following permission sets:

Prompt Template Manager – for users who create and manage templates

Prompt Template User – for users who run the templates

You can assign these via:

Setup → Permission Sets → Manage Assignments

What Is Salesforce Prompt Builder and How to Enable It?

Once these steps are complete, you’ll see Prompt Builder available in Setup—and you’re ready to start designing AI-powered templates!

What Is Salesforce Prompt Builder and How to Enable It?

What Is a Prompt—and Why Writing It Right Matters

In the age of AI, the word “prompt” has taken on a whole new level of importance. Whether you're chatting with an AI assistant, generating images, or building automation workflows, prompts are the bridge between your intent and the machine’s output. But what exactly is a prompt—and why does writing it the right way make all the difference?

What Is a Prompt?

A prompt is a piece of input or instruction given to an AI system to guide its response. Think of it as a question, command, or description that tells the AI what you want. It can be as simple as:

“Write a poem about the moon.”

Or as complex as:

“Generate a 500-word blog post explaining the importance of cybersecurity for small businesses, using a friendly tone and real-world examples.”

In essence, a prompt is your way of communicating with AI—your words become the blueprint for its output.

Why Writing the Right Prompt Is Crucial?

Crafting a good prompt isn’t just about typing something and hoping for the best. It’s about being intentional, clear, and strategic. Here’s why it matters:

Precision Drives Quality

A vague prompt leads to vague results. If you say “Tell me about marketing,” the AI might give you a generic overview. But if you say “Explain digital marketing strategies for B2B startups in 2025,” you’ll get a focused, relevant answer.

Context Shapes Creativity

AI thrives on context. The more details you provide—tone, audience, format, purpose—the better the output. For example:

“Create a formal email to a client about project delay” vs.

“Write a casual update to a teammate about running late on a task”

Same topic, different tone—prompting makes the difference.

Saves Time and Reduces Rework

A well-written prompt minimizes back-and-forth. Instead of refining outputs repeatedly, you get closer to your goal on the first try. This is especially important in professional settings where time is money.

Unlocks Advanced Capabilities

Want to generate code, design a logo, or simulate a business scenario? The right prompt can unlock powerful features. For example:

“Generate Python code to scrape product prices from an e-commerce site and store them in a CSV.”

That’s not just a request—it’s a command that activates a specific skill set.

Tips for Writing Better Prompts

Here’s how to level up your prompting game:

Be specific: Include keywords, constraints, and goals.

Define the format: Blog post, list, email, poem—tell the AI what structure you want.

Set the tone: Formal, friendly, persuasive, humorous—tone matters.

Clarify the audience: Is it for beginners, experts, clients, or students?

Use examples: If possible, show what you mean.

Final Thoughts

Prompts are not just inputs—they’re instructions, inspirations, and invitations. Writing them well is a skill that empowers you to get the most out of AI tools. Whether you're a developer, marketer, educator, or just curious, mastering the art of prompting is your gateway to smarter, faster, and more creative results.