function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jordan VasquezJordan Vasquez 

Problem passing HTML text to Rich Text Field using Apex

Hey everyone,

I currently set up an integration with VSTS and I have been having issues passing basic HTML to a Salesforce Rich Text field and I was hoping to be pushed in the right direction.

According to this document I believe basic tags like <b>, <u>, and <i> should be able to be passed in but I cannot get it to work for the life of me. Is there anything that should be done?

This is the String value that I am attempting to pass into my Rich Text Field:
'This is a test. <b>BOLD </b><i>Italicized</i><u>Underlined</u> This was a test.'



 
Jordan VasquezJordan Vasquez
To clarify, the end result in my Rich Text Field is the following without any formatting! All tags are being removed after being added to my Rich Text Field:
 
This is a test. BOLD ItalicizedUnderlined This was a test.

 
Sabarinathan NSabarinathan N

Below is working for me. Please try like below.

RechTextbox= VarName+ '<b>' + Var2+ '</b>:<br/> ' + Var3 + Var4;

Jordan VasquezJordan Vasquez
Hey Sabarinathan, I finally managed to get this to work in my org but I am running into another issue when using a <span> tag.

I am trying to build this:
'This is <span style="font-weight:bold;\\">Some more </span>verbiage <span style="text-decoration-line:underline;">under the&nbsp;</span>&nbsp;rich <span style="font-style:italic;">text field.</span>'

If I pass that into my Rich Text field like this...it works...
String var1 = 'This is <span style="font-weight:bold;">Some more </span>verbiage <span style="text-decoration-line:underline;">under the&nbsp;</span>&nbsp;rich <span style="font-style:italic;">text field.</span>';

BUT if I try to pass it in like this where the line above is within a map...it does not work....
String var1 = (String)map.get('richtextfieldvalue');

Do you know any reason why it might be behaving in this manner? I don't see why it is any different, I am passing the same exact value at the end of the day.

 
V TV T