1

Question

In a workflow formula criteria, what's the expected behavior when comparing nulls with the <> operator?

Details

I've got a basic workflow that seems like it should fire but unexpectedly doesn't. Looking at the debug logs doesn't help clarify the issue.

Workflow is a "simulated" formula field to pull the value from a parent record down to a child. It's setup to fire every time the child field doesn't match the parent then copy the field down to the child. I've got a nearly identical workflow on another field which is working fine, but this one isn't working.

Workflow Setup

  • Object: Child__c
  • Evaluation Criteria: Every time it's edited
  • Rule Criteria: Field__c <> Parent__r.Field__c

Debug Log (altered for readability)

02:51:30.849 (3849934225)|
> WF_FORMULA|
> Formula:ENCODED:[treatNullAsNull] 
> Field__c <> Parent__r.Field__c|
> Values:Field__c=null, Parent__r.Field__c=100
02:51:30.849 (3849942426)|WF_CRITERIA_END|false

Debug Log (raw)

02:51:30.849 (3849934225)|WF_FORMULA|Formula:ENCODED:[treatNullAsNull]{!ID:00N50000002aEzl} <> {!ID:00N50000002aBwS.00N50000002aEzz}|Values:Max_Defensive_Posture_Fixed_Percent__c=null, Strategies__r.Max_Defensive_Posture_Fixed_Percent__c=100
02:51:30.849 (3849942426)|WF_CRITERIA_END|false

Discussion

This isn't terribly hard to work around (just change the formula to true), but the behavior is perplexing, and I'm hoping someone out there has seen this enough to comment on what's going on (as opposed to just suggesting work arounds). 100 <> null -> false feels far too 1984-esque comparison could really use an explanation for me and the community.

3
  • Side note, but this won't fire if the field on the parent object is changed - is that intentional? – Davin Casey Sep 5 '14 at 10:28
  • Kind of, in that I knew that was the case, and considering it now, that actually would be the desired behavior. Use case is kind of like list price ..., only want to update it based on the parent changing when they're re-editing the deal. – Ralph Callaway Sep 5 '14 at 10:33
  • Fair enough, just thought I'd mention it. – Davin Casey Sep 5 '14 at 11:18
2

The workflow formula UI doesn't seem to have a "treat blank values as zeros" checkbox, which I always assumed that it did. Anyway, the debug is showing:

Formula:ENCODED:[treatNullAsNull] 

and you don't seem to be able to do comparisons on nulls.

Maybe this will work:

BLANKVALUE(Field__c,0) <> BLANKVALUE(Parent__r.Field__c,0)

Which is just explicitly treating blank values as zeros.

3
  • Any chance you can elaborate on "you can't do comparisons on nulls?". Does that mean anything <> null always returns false? What about anything = null does that already return false to? Blank value approach sounds like it will work for some users, at least in my case, if the parent value is null, i want that copied down as null to the child, i.e. null <> null -> false, null <> 100 -> true, 0 <> null -> true. Is there a known issue or documentation referencing this? – Ralph Callaway Sep 5 '14 at 10:30
  • 1
    I don't think it's an issue as such, it's just "how it works". My experience, not backed up by any documentation at all, is that it's best to do something explicit with the BLANKVALUE in workflow formulas. I think that it will always return false. And I've edited my answer to reflect that I'm not nearly as sure about this as I sounded. – Dominic Sep 5 '14 at 10:38
  • Totally, just hoping you might be able to elaborate on what "how it works" means, less concerned with lack of treat blank values as zeros, than the null comparison not working like you'd think ... – Ralph Callaway Sep 5 '14 at 10:46

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.