[SalesForce] I need a String method in a Trigger to validate if a Rich Text Area is blank

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?

Best Answer

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));