[SalesForce] Error Handling for NULL/Blank field values in Process Builder

I have an issue where I'm trying to check for a field value prior to sending it to my Flow in order to avoid an uncaught error message but it seems that even when I reference the field in a formula, like so:

IF( 
    ISBLANK([Order].Opportunity.Site_Contact__c.Email),
    '', [Order].Opportunity.Site_Contact__c.Email
)

It still gives me the following error:

The flow failed to access the value for myVariable_current.Opportunity.Site_Contact__r.Email because it hasn't been set or assigned.

Is there not a way to check this before sending it to the Flow. I would rather not have to update my flow to be specific, cause currently I use this flow to send other emails through as well.

Best Answer

When checking field values of a related object through a custom lookup, you have to:

  • First check if the lookup field value is not null
  • Reference the related field using __r.Field rather than __c.Field

You'll run into these errors trying to reference a field through a lookup that is null.

In this case, since this is a multi-level lookup, you'll want to check that OpportunityId on the Order is not blank, that Site_Contact__c on Opportunity is not blank, and then finally, if Email on the Contact is not blank. Based on your original formula, something like this should work.

IF(
    OR(
        ISBLANK([Order].OpportunityId),
        ISBLANK([Order].Opportunity.Site_Contact__c),
        ISBLANK([Order].Opportunity.Site_Contact__r.Email)
    ),
    "",
    [Order].Opportunity.Site_Contact__r.Email
)