Agentforce provides multiple features to automate repetitive service and sales tasks by drawing on data from past cases, recent purchases, product changelogs, and real-time case notes. Apart from standard, out-of-the-box features, developers can also use Einstein Generative AI and Prompt Builder to implement custom solutions that support different business use cases.
Take one sales representative task, for example. Sales reps often need to review changes happening to Account records and others, requiring them to find, open, and read through every record related to the account. This process is quite time consuming, and that’s where Flex prompt templates can make a huge difference.
In this post, we’ll show you how to use an Einstein Generative AI-powered Flex prompt template to compare prior and current values of a record and summarize any changes made to the record.
Prepare a prompt template
Before getting started, you’ll first need to sign up for a Salesforce Developer Edition org, and then enable Generative AI.
- Go to Setup → Search Einstein Setup → Enable Einstein
If you are not using a Developer Edition, and if your user profile is not System Administrator, then assign yourself the Prompt Template Manager permission set to access Prompt Builder.
Now, create a Flex prompt template for data comparison.
- In Setup, search for Prompt Builder and click New Prompt Template
- Select Prompt Template Type as Flex, enter template name as Summarize Records Changes, and provide a description
A Flex prompt template is a very flexible prompt template that can accept different data types as input. Since the two record sets need to be compared, we’ll create two input fields.
- Create input fields Original Record and Updated Record, with Source Type as Free Text for both
- To provide additional context in the summary, let’s add another input: the name of the user who changed the record
- Click Next and then provide instructions, participants, context, and goals to the prompt for data comparison
Paste the following instruction into the prompt template text area field.
Convert records to JSON
To send string data to the Flex prompt template, we’ll need to convert the record data to JSON with Apex. For that, write an invocable method to convert the record (an SObject class) into JSON. The invocable method can then be called in a flow.
Create a record-triggered flow
The final step is to connect all components and create a record-triggered flow on the target object (Account in our case). Since the objective is to compare changes made to the record, it is necessary to generate JSON for both the original and the updated record values, hence the Apex action should be invoked twice: once with the original record values and once with the updated values.
After the JSON is generated, add an action that calls the Summarize Record Changes Flex prompt template. The prompt compares input data, summarizes the record changes, and returns the generated summary. This generated summary can then be stored in a custom field using an Update Record action.
Enjoy a smart summary for every record update
With this Flex prompt template-powered flow, every time a record is updated, your system will automatically compare changes between the old and new data. It will then generate a human-readable summary and store it in the Record Summary field.
Now, your sales representatives can instantly understand what changed — no need to dig into record history!
Conclusion
The use of the Flex prompt template will save a developer’s time by not having to write complex code in Apex and instead enable a flow to compare JSON and generate change summaries. The auto-generated version history saves a sales representative’s time by eliminating the need for manually navigating through historical records to review the changes. Einstein Generative AI can be used to accelerate implementation in several use cases; every developer just needs to identify the right use case.
Resources
- Overview: Prompt Builder
- Trailhead: Get Started with Prompts and Prompt Builder
- Documentation: Prompt Builder
- Salesforce Admins blog post: The Ultimate Guide to Prompt Builder
About the author
Pradnya Desai is a Senior Technical Architect at Salesforce who specializes in the analysis, design, and development of cross-cloud solutions using Agentforce, Einstein Bots, and OmniStudio. Connect with her on LinkedIn.