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 start your AI Journey?

Table of Contents Introduction Are you tired of the same old world? Do you dream of painting landscapes with your code, composing symphonies with data, or...

The Secret Weapon: Prompt Engineering: 🪄

Table of Contents Introduction Crafting the perfect prompt is like whispering secret instructions to your AI muse. But there's no one-size-fits-all approach! Exploring different types of...

How to Singup for your own Production org?

Let's see how we can have our salesforce enterprise Salesforce Org for a 30-day Trial and use it as a Production environment. With the...

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