[SalesForce] Process Builder: Immediate Actions Criteria for Updating Records not working as expected

In my Org I have Custom_Object_A__c and Custom_Object_B__c. Custom_Object_A__c has a Lookup field to Contact and another Lookup field to Custom_Object_B__c. Custom_Object_B__c also has a Lookup to Contact.

I have a Trigger on Custom_Object_A__c which fires on Insert that looks at the two Lookup fields, if the Lookup to Contact is null, and the lookup to Custom_Object_B__c is populated, then I populate Custom_Object_A__c's Contact field with the value that is set in Custom_Object_B__c.

I am trying to move this functionality to the Process Builder. What I have so far…

  1. Custom_Object_A__c: Only when a record is created.
  2. Criteria: No criteria—just execute the actions!
  3. Immediate Actions: Update Record that started the Process.
  4. Criteria for updating records: Updated records meet all conditions

    • Lookup to Contact is null Boolean true
    • Lookup to Custom_Object_B__c is null Boolean false.
  5. Set new field values for the records you update

    • Lookup to Contact
    • Type: Reference
    • Custom_Object_B__c.Contact ID

Criteria
Immediate Action

As best I can tell this should ONLY set the Contact Lookup on Custom_Object_A__c if on creation the Contact Lookup is null AND the Custom_Object_B__c Lookup is NOT null.

However when I try creating a test record for Custom_Object_A__c with the Contact Lookup filled, and the Custom_Object_B__c null I get an error

The record couldn’t be saved because it failed to trigger a flow

I also get an email stating

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

I don't understand why it's even trying to look for this relationship?

Any ideas as to why this is happening?

Best Answer

I would move your criteria to the criteria diamond. In your case, since you need to have set department fire for every record, you'll need two branches to handle this.

  1. The first criteria will handle your criteria for Set Contact, so Contact is null, and Custom_Object_B__c.Contact__c is not null. Your immediate action will be "Set Contact" and "Set Department."
  2. The second criteria will fire with no criteria, this will catch all records that need to be updated with only the "Set Department" action.
Related Topic