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
khillan bhardwajkhillan bhardwaj 

Getting Plain text from rtf text in trigger

Hi,

I want to get plainText from rtf text in the trgger.the rtf text is present the the custom fields as below:

{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Tahoma;}} {\*\generator Msftedit 5.41.21.2510;}\viewkind4\uc1\pard\f0\fs17 Ben called with updated CC info 7/3/14...going forward use\par \par 4856 3100 1190 8431 \par exp 12/16 \fs17 }

Can any let me know how to get plainText from this rtf text.

Thanks
Khillan 
surasura
try stripHtmlTags(); method 
 
String s1 = '<b>hello world</b>';
String s2 = s1.stripHtmlTags();
System.assertEquals('hello world', s2);


 
khillan bhardwajkhillan bhardwaj
Hi, Thanks for reply. I have try this method allready.

stripHtmlTags(); method of string eliminate html tags only.It does not work for rtf text.

Thanks
ManojjenaManojjena
Hi Khilan,

What exactly your requirment you need to assign the richtextArea value to TextArea right ? and the value in you RichTextArea  is that you have given above .
I think the method sura has given will  work that I have already used before .

Check with below poc .it is working .
 
trigger RichTextAreaTest on Account (before Insert,before update) {
    for(Account acc : trigger.new){
        acc.TextArea__c =acc.RichtextArea__c.stripHtmlTags();
        
    }
}

 
khillan bhardwajkhillan bhardwaj
Hi Manoj,

I have richText value in textArea field. I need to remove rich text to extract the usable information.

For Example in the textArea i have value as below:

{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Tahoma;}} {\*\generator Msftedit 5.41.21.2510;}\viewkind4\uc1\pard\f0\fs17 Ben called with updated CC info 7/3/14...going forward use\par \par 4856 3100 1190 8431 \par exp 12/16 \fs17 }

From this rtf text i need to extract information:

Ben called with updated CC info 7/3/14...going forward use
4856 3100 1190 8431
exp 12/16


but the method you provide stripHtmlTags remove only html tags only.

Hope this make sense.

Thanks