How to create a Text Rich Area field in flow?

on

|

views

and

comments

Hello There,

As we know that we can not create a rich text area field in Salesforce Lightning flow. In this blog post, we will see how we can use a Lightning web component to act as a rich text area.

Complete Code

You will get the complete code from Here.

Create a Lightning Web Component

Create a LWC component and name it richTextArea or you can give it any other name as well.

For the .js-meta.xml field use below code

<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>51.0</apiVersion>
    <isExposed>true</isExposed>
    <masterLabel>Rich Text Area</masterLabel>
    <targets>
        <target>lightning__FlowScreen</target>
    </targets>
    <!-- Configuring the design attributes -->
    <targetConfigs>
        <targetConfig targets="lightning__FlowScreen">

            <property name="label" type="String" label="Label to Display" default="Message" 
                        description="The Lable to display"/>
            <property name="placeholder" type="String" label="Enter the Place Holder" 
                        description="Enter the Place Holder to display inside text area rich"/>
            <property name="value" type="String" label="Value to show on text area rich or get from text area rich"
                        description="Value to show on text area rich or get the value from LWC to Flow Builder"/>
            <property name="required" type="Boolean" default="false" label="Required?"
                        description="Indicates if the text area rich field is required or not?"/>
            <property name="requiredMessage" type="String" default="⚠️ Value is required for this field" 
                        label="Message when value missing" 
                        description="The error message to be displayed when the value is missing if the field is required."/>
            
        </targetConfig>
    </targetConfigs>
</LightningComponentBundle>

Code Explanation

SnPropertyUsage
1labelThe label to display for Rich Text Area field
2placeholderPlaceholder
3requiredIndicates either the field is required or not
4requiedmessageIf required, which message we need to display to user if the field is blank

To execute the flow action and for flow support we need to import some actions from lightning/flowSupport library

import { FlowAttributeChangeEvent, FlowNavigationNextEvent, FlowNavigationFinishEvent, FlowNavigationBackEvent, FlowNavigationPauseEvent } from 'lightning/flowSupport';

to perform the validation for the field, we need to use a method with @api anonation in salesforce lwc javascript.

@api
    validate() {
        if( this.validateInput() ) { 
            return { 
                isValid: true 
            }; 
        } else { 
            return { 
                isValid: false, 
                errorMessage: this.requiredMessage 
            }; 
        } 
    }

Configure Component in Flow

  1. Create a flow or edit the flow where you wanted to use the rich text area field.
  2. Drag & Drop the LWC inside the Screen element

Complete Code

You will get the complete code from Here.

Thanks for reading. Happy Learning

Amit Singh
Amit Singhhttps://www.pantherschools.com/
Amit Singh aka @sfdcpanther/pantherschools, a Salesforce Technical Architect, Consultant with over 8+ years of experience in Salesforce technology. 21x Certified. Blogger, Speaker, and Instructor. DevSecOps Champion
Share this

Leave a review

Excellent

SUBSCRIBE-US

Book a 1:1 Call

Must-read

How to Utilize Salesforce CLI sf (v2)

The Salesforce CLI is not just a tool; it’s the cornerstone of development on the Salesforce Platform. It’s your go-to for building, testing, deploying, and more. As one of the most important development tools in our ecosystem

Save the day of a Developer with Apex Log Analyzer

Table of Contents What is Apex Log Analyzer? Apex Log Analyzer, a tool designed with Salesforce developers in mind, is here to simplify and accelerate your...

Salesforce PodCast

Introduction Hey Everyone, Welcome to my podcast, the first-ever podcast in India for Salesforce professionals. Achievement We are happy to announce that we have been selected as Top...

Recent articles

More like this

13 COMMENTS

  1. This seems to work fine for formatted text, but any images I paste into the field get removed when I try to add the contents of this component to a Rich Text field in SFDC. Any ideas of how to get around that?

  2. I apologize, but I do not understand. After pasting the image into the Rich Text field, I need to type something in order for SalesForce to accept the field contents instead of removing the image?

      • OK. I pasted an image into my Rich Text Field in my Screen Flow. I saved the contents of the field into a variable. I then saved the contents of that variable to a Rich Text field on the Case object. When I did that, and then viewed the case record, I was told that the image was removed from the field on the case. Where did I go wrong?

    • Does this rich text field support merge fields? Based on your video on this I don’t see that it gives you the option to insert resources, but if I type in the text with the merge field formatting, will it actually pull the info from the record onto the email?

LEAVE A REPLY

Please enter your comment!
Please enter your name here

5/5

Stuck in coding limbo?

Our courses unlock your tech potential