Is it possible to insert colored text into a Rich Text Box via apex (trigger)? I know that one can insert bold and other tags and it works.


2 Answers 2


I am not sure if it is a perfect answer. But here is how I done it.

a.MyRichTextField__c = 'My <span style="color:red"> RED</span> colored line';

Where MyRichTextField__c is the rich text field.


Rich text fields store HTML in the backend, so if you save in some relevant HTML that includes some div/spans with some CSS in style attributes you should see the colours on screen.

e.g. store the following HTML into a rich text field (written in via code (Apex Trigger) or some other means, not in the editor itself).

<span style="display: inline-block; background-color: #00f; color: #fff;">Hello, World!</span>

trigger AccTrigger on Account (before insert, before update) {
    for(Account objA : Trigger.New){
        objA.RTA__c = '<span style="display: inline-block; background-color: #00f; color: #fff;">Hello, World!</span>';

You must log in to answer this question.

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