5

I need assistance in evaluating whether a Rich Text Area custom field is blank using an Apex trigger.

Rich Text Field name: Application_Workaround__c

I have tried the following within the context of a trigger:

string.isBlank(new_application_dependency_record.Application_Workaround__c) 

This method returns "true" if there is a single break within the rich text field "Application_Workaround__c". THe problem is that the
tag in the rich text field is not a valid value but the string method considers it to be a non-blank.

I also tried the following:

string.valueof(new_application_dependency_record.Application_Workaround__cApplication_Workaround__c).length() == 0;

I also tried:

string.new_application_dependency_record.Application_Workaround__cApplication_Workaround__c.length() == 0;

None of these methods seem to ignore blank space or the <BR> tag.

What is the best practice for determining if a rich text field is truly blank?

4
  • 2
    Have you tried trim? Something like String.isBlank(new_application_dependency_record.Application_Workaround__c.trim())?
    – JCD
    Commented Feb 11, 2013 at 20:48
  • Thanks for the quick reply. The underlying problem I am facing is the scenario where a user enters a line break or tries to delete all characters in the field yet a single or multiple "<BR>" HTML <BR> tag is still stored in Rich Text Field when you try to access that Rich Text Field in Apex using something like Object.FieldName. I don't believe that TRIM will remove the "<" or ">" characters as they are not "white space". Commented Feb 11, 2013 at 21:47
  • I think its a known issue with rich text boxes that they are never truly blank. Since you know that it contains the <br/> tag, can't you assume that its blank in this case?
    – Richard N
    Commented Feb 12, 2013 at 0:41
  • sites.secure.force.com/appexchange/…
    – Richard N
    Commented Feb 12, 2013 at 0:47

1 Answer 1

3

You can remove all html tags (or just br if you want) and use isblank so that whitespace is not an issue.

String richtextstr = string.valueof(new_application_dependency_record.Application_Workaround__cApplication_Workaround__c);
richtextstr = richtextstr.replaceall('<.*>','');
string.isblank(richtextstr));

You must log in to answer this question.

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