0

This is probably super simple but I can't figure it out. I am combining the text from two rich text area fields into a long text area field and I am getting all the formatting tags in the result. Is there an easy way to get just the text from the rich text area field?

     string msgToSup = 'Privacy Officer Message: ' + SPM.Message_To_Supervisor__c 
        + '\n\n' + 'Security Officer Message: ' + SPM.Security_Officer_Message_to_Supervisor__c
        + '\n\n' + '***Please see the PDF in the Files section for event details.***';

Results in this: enter image description here

3
  • a RTF is by definition going to have HTML tags. What is the intended destination of the msgToSup? If part of an HTML email, you'll want the tags
    – cropredy
    Commented Jan 5 at 20:31
  • how did you bind in to UI, can you provide Html code ?
    – sdandamud1
    Commented Jan 5 at 20:44
  • @sdandamud1 It's literally just a plain text field on a record detail page.
    – sfdcfox
    Commented Jan 5 at 20:54

1 Answer 1

2

You can use the stripHtmlTags() function to remove all HTML tags.

 string msgToSup = 'Privacy Officer Message: ' 
    + SPM.Message_To_Supervisor__c.stripHtmlTags()
    + '\n\n' + 'Security Officer Message: ' 
    + SPM.Security_Officer_Message_to_Supervisor__c.stripHtmlTags()
    + '\n\n' + '***Please see the PDF in the Files section for event details.***';
1
  • Thanks sfdcfox, you always have the easiest solutions!
    – Matt M
    Commented Jan 5 at 21:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .