6

Process builder bombs if you try and access a value on a parent relationship record on a record without a value for the parent relationship. For criteria this is easy to avoid by first checking that the lookup is not equal to null (see Check if lookup field is not null in Process Builder)

But, this doesn't seem to work in formulas. I've got the following

ISPICKVAL([CampaignMember].Status, 'Responded') &&
NOT(ISBLANK([CampaignMember].LeadId)) &&
NOT(ISPICKVAL([CampaignMember].Lead.Status , 'New')) &&
OR(
 CONTAINS(LOWER([CampaignMember].Campaign.Name),'Name1'),
 CONTAINS(LOWER([CampaignMember].Campaign.Name),'Name2'),
 CONTAINS(LOWER([CampaignMember].Campaign.Name),'Name3')
)

If I update a campaign member that's related to a contact (and hence [CampaignMember].Lead is null) I get the following error

The flow failed to access the value for myVariable_current.Lead.Status because it hasn't been set or assigned.

However, I thought this wouldn't happen since NOT(ISBLANK([CampaignMember].LeadId)) is evaluated before NOT(ISPICKVAL([CampaignMember].Lead.Status , 'New')).

I've tried using ISNULL as well with the same the same result. Now, I'm stuck, what's the proper way to access [CampaignMember].Lead.Status to avoid issues with null lead lookups?

  • I recommend you be more consistent and use AND rather than && (since you already use OR over ||). Doubt it would solve your issue but I find it easier to read (and somewhat advantageous to be more obviously distinct from code syntax). – Adrian Larson Apr 18 '18 at 18:31
  • @AdrianLarson i think i'm going need a vote on the question before getting code style advice ;-) – Ralph Callaway Apr 18 '18 at 18:33
6

Normally, Process Builder does do short-circuit evaluation on Boolean expressions, so this is an effective way to guard against null references.

I tried to reduce this to a minimal example, and the issue appears to be that the ISPICKVAL() function is evaluated before Boolean short-circuiting.

A Process Builder with this formula-based condition works correctly when inserting a Campaign Member with a blank Lead lookup:

NOT(ISBLANK([CampaignMember].LeadId)) && [CampaignMember].Lead.LastName = "Test"

while this one fails:

NOT(ISBLANK([CampaignMember].LeadId)) && ISPICKVAL([CampaignMember].Lead.Status, "Test")

The same is true of using the TEXT() formula against Lead.Status; the formula function is evaluated first, resulting in the null exception.

One workaround is to create a Text field Status_Text__c on Lead, whose value is TEXT(Status). Your formula can then evaluate the field without calling a formula function in Process Builder:

NOT(ISBLANK([CampaignMember].LeadId)) && [CampaignMember].Lead.Status_Text__c = "Test"

(I confirmed that this works; this is a wrinkle to Process Builder evaluation I hadn't met before).

  • 3
    process builder never ceases to surprise with special edge cases, kudos for the fine research!! – Ralph Callaway Apr 18 '18 at 19:02

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.