4

Trying to figure out why this formula:

!ISBLANK(TEXT( At_Risk__c)) || !ISNULL(TEXT(At_Risk__c))

Evaluates to true when the value for the picklist At_Risk__c is null as shown in the debug log:

WF_CRITERIA_BEGIN [Account: Sam Test 001g000000QwD0T]|TestFormula|01Qg00000001AC3|ON_ALL_CHANGES|0
WF_FORMULA Formula:ENCODED:[treatNullAsNull]!ISBLANK(TEXT( {!ID:00Nb0000009bOgb})) || !ISNULL(TEXT({!ID:00Nb0000009bOgb}))|Values:At_Risk__c=null
WF_CRITERIA_END true

Anything I might be missing? Or not understand the functionality.

2 Answers 2

2

It appears to me as though you're running this on an encoded field. That in and of itself complicates this a bit. First off, I don't believe you can encode a field with a null value. I'd expect you'd get a null pointer exception of some kind if you attempted to do that. Since it's a string, the only thing that's relevant is whether or not it's blank. Try removing the null portions of your validation rule and see if doesn't work properly once you do.

Also, as an FYI, the best practice according to Salesforce is to use IsBlank whenever a text string is being evaluated as that covers both empty strings and what you'd think of as null values.

For more on encoding, see these two links from the Apex Code Developer's Guide on Encoding and the Encoding Utility Class: Encoding Your Data and EncodingUtil Class. There are a number of kinds of encoding including string to Blob (Base 64), Convert to Hex, URL encode, JsEncode and more. These can involve the crypto class.

Essentially, encoding involves converting the data from it's existing form into another entirely different form that makes it unreadable through normal means. In the case of a Blob, this is in part done for efficiency of storage. In other cases, it's done for the purpose of secure transmission via web protocols. Regardless, when you look at the links, you'll notice that a null pointer exception is one of the things that can be problematic, especially when converting from Hex 64 back to a string.

5
  • Thank you for your response, I've removed where it checks for null. Can you expand a little bit about encoded fields? Commented Mar 12, 2015 at 15:00
  • See my edited response.
    – crmprogdev
    Commented Mar 12, 2015 at 15:27
  • I think I was a bit vague with my previous comment, sorry. The question that I wanted to ask is why is the keyword ENCODED in the debug log? I haven't set the field to be encoded, at least not that I know of so is it Salesforce who encodes the value in the field? Commented Mar 12, 2015 at 15:40
  • I'd expect it's being encoded by Salesforce at your request most likely via some kind of data handler (esp if it's an attachment), or else it's a datatype of some kind that's coming from a source which one would expect to be encoded. Without knowing more details, it would be difficult for me to say. I'd simply be guessing.
    – crmprogdev
    Commented Mar 12, 2015 at 17:55
  • 1
    I think it is much easier. I believe SFCD takes your formula as text and converts it to the real data (At_Risk__c > ID:00Nb0000009bOgb). Commented Mar 13, 2015 at 7:47
5

You should not use ISNULL. It not working correctly with a text:

Use ISBLANK instead of ISNULL in new formulas. ISBLANK has the same functionality as ISNULL, but also supports text fields. Salesforce will continue to support ISNULL, so you do not need to change any existing formulas.

And following:

Text fields are never null, so using this function with a text field always returns false.

So I think in your case it is like:

!ISBLANK(TEXT( At_Risk__c)) = NOT(TRUE)  = FALSE
!ISNULL(TEXT(At_Risk__c))   = NOT(FALSE) = TRUE

One of the both conditions is TRUE and the formula returns TRUE.

You must log in to answer this question.

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