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
Sn | Property | Usage |
1 | label | The label to display for Rich Text Area field |
2 | placeholder | Placeholder |
3 | required | Indicates either the field is required or not |
4 | requiedmessage | If 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
- Create a flow or edit the flow where you wanted to use the rich text area field.
- 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 from the blog SFDCPanther.com has written a post explaining how to create a LWC that will enable a Rich Text Area component in flow screensCheck it out […]
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?
Hi Jonathan,
After pasting the image you need to make sure that you are on the correct line to type the text. I have tried and this is working fine.
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?
No, You do not need to. If you are pasting the image and also having text then you need to type. Otherwise it should work fine.
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?
Hi Jonathan,
I have again validated the same and it’s working. Are you available for a quick call I can see what you are doing wrong. Email me at info@pantherschools.com
I am seeing the same issue as Jonathan. Were you able to determine a solution?
Jonathan was getting the error because he was using the flow inside Community and Flow was not active
[…] Code for the Lightning Component for the Flow […]
Thank you so much! This thing is awesome; exactly what I needed.
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?
Hi Alex,
This component does not support the merge fields concept for now however thanks for giving the idea.