We're using the "Solutions" standard object as our knowledge base, with "Solution details" standard field is a Rich Text Area field (32000 characters).

The field structure looks like this:

Purpose (header 1)


Appropriate versions (Header 2)

text: version numbers.

Additional Details (Header 3)


What I want to do is update the text under "header 2" without the need to enter to each solution and field and type the versions manually. I created a custom picklist field called "versions", and tried copying the picklist value into the "Solution details" field via workflow rule and field update - the problem is that it causes losing all HTML and turns this field to text only. I understood it's possible to update this without loosing HTML only with trigger. Did anyone accomplished something similar? are there even "Substitute" / "replace" functions in triggers??

  • For anyone working on richtext and not understanding why code is required, workflow field updates and formulas don't work on rich text fields. Apr 7, 2013 at 18:24

1 Answer 1


Yes, APEX, the language used to write triggers, supports find and replace. String types (which include rich-text fields) have a number of options, primarily String.replace() and String.replaceAll() (see the String methods for the full list). You also use Pattern and Matcher classes that can do more complex regex related activities (see the Pattern and Matcher docs).

Basic Example

trigger YourTrigger on Solution (before update) {   
  for(Solution s : trigger.new) {
    s.replaceAll('Hello World','Goodbye World');

More Info

If you're looking to explore what other functionality is available, you'll want to have the APEX API Reference handy.

  • thanks @ralph, can you share an example of how to find a string within two strings? (In this case it is Header 2 and 3)
    – Itay B
    Apr 7, 2013 at 21:23
  • take a look at indexOf in the string methods link in the answer, i think that's what you're looking for Apr 8, 2013 at 7:58

You must log in to answer this question.

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