2

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)

text..

Appropriate versions (Header 2)

text: version numbers.

Additional Details (Header 3)

text..

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. – Shane McLaughlin Apr 7 '13 at 18:24
3

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 '13 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 – Ralph Callaway Apr 8 '13 at 7:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.