1

Using LEN() function, we are able to validate if a rich text area is blank, but when a rich text area with image is added, LEN() still say 0.

How to validate whether rich text area field contains image or not ?

1

Wrote a trigger to validate rich text area to check for image or not

trigger JobTrigger on Job__c (before update) {

       for(Job__c j: Trigger.newMap.keySet()){

        if((Trigger.oldMap.get(j).Status__c != Trigger.newMap.get(j).Status__c) 
                 && (Trigger.newMap.get(j).Status__c == 'Completed'))
         { 

          if(j.Picture__c != null){

             String picString = j.Picture__c.substringBetween('<img', 'img>');

              if(picString == null ){
               j.addError('Picture is required to move Status to Completed');
              }
          }

       else {

         if(picture__c == null ){
              j.addError('Picture is required to move Status to Completed');
           }

          }
        }
      }
    }
0

You can use isEmpty(). If it's length is 0 and it's not empty, it must contain something which could be an image.

  • There is no IsEmpty() function in Validation rule. – sfdc Jun 23 '16 at 14:33
  • Darn, was thinking of Apex. There's an isBlank in Validation Rules is there not? You may want to try that. Null might do it as well. In Apex isEmpty covers Blank, and Null. – crmprogdev Jun 23 '16 at 15:09
  • IsNull and Isempty doesn't work as well. – sfdc Jun 24 '16 at 17:28
  • 1
    A Formula should allow either ISBLANK or BLANKVALUE. Both are referred to as "Informational Functions". ISBLANK returns a Boolean Result. BLANKVALUE determines whether an expression has a value and returns a substitute expression if it doesn't. If it has a value, it returns the value. Since a RTF doesn't work exactly like a string, I'm not certain there's a solution other than using a trigger to search for a blob. – crmprogdev Jun 24 '16 at 18:36

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.