5

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.

Thanks

8

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.

8

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>';
    }
}

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.