Process Builder Errors and Weirdness
Oh those dreaded process builder errors. They are sooooo annoying. You spend so much time and effort building a great solution for your users and all that good work is undone with a badly worded error message. What can the user even do about this - there is nothing they can do except undo what they were trying to do and get frustrated and annoyed.
(screen shot taken in Summer '16 version of Salesforce - with the horrible vertical nav).
(screen shot with classic).
This post puts it well http://www.ezrakenigsberg.com/blog/makingsenseofprocessbuildererrormessages and gives us an idea of how we can find which Flow (ah, Process) is causing the error.
in the email the error is a liltle more informative.
An error occurred at element myRule_1_A1 (FlowRecordUpdate).
The flow failed to access the value for myVariable_current.Campaign.Description because it hasn't been set or assigned.
So at least, once we know what process it is that caused this error, we can see that it has something to do with Campaign or Description.
TL:DR
Just use this in your criteria
(This article gives a bit more info on this option https://salesforcesidekick.com/2016/07/11/how-to-work-with-related-records-in-process-builder-criteria/)
Or this in your update
To get around this horrible horrible error. Now read on for the full details.
Why this Post
I really don't know why the examples in this post worked 90% of the time. Prior to this I had just about rage quit process builder. I had tried everything possible, or so I thought. I had even re-made processes into flows just to get around this error (as per the example below). Maybe it was because my real world attempts were based on multiple fields that obfuscated what the actual problem is. Maybe by simplifying the process (as per the rules of debugging), that's why I could get it to work more often. I dunno. But next time I do a more complex PB and come a cropper I will update this post.
Making this Error
It was so simple to create a process that gave an error like this. This would be something that you would do in workflow in a snap. All I tried to do was to set the Opportunity Description to be the Description from the Campaign - now, you would probably not do this in real life, but I knew this would create this hasn't been set or assigned
error.
So this process runs on the Opp Object and runs whenever the record is created or edited - with no additional criteria and tries to set the Description field to the description from the related Campaign.
The opportunity record I edited had no Campaign, so there was no description to be found, so it errored. Workflow would just put blank in there - as it should. WHY OH WHY does this cause an error in Process Builder? As soon as I add a Campaign to the Opp, this error disappears and it happily updates the description field.
I recreated the exact same process in a flow and it did not have an error at all. It even degraded nicely and deleted the value in description when I removed the Campaign from the Opp.
The flow takes in the param of the Opp ID, looks up the Opp to find the Campaign ID, then looks up the Campaign to find the Description, then updates the Opp with the Campaign Description. Easy.
So I created the same thing in a Workflow (this example can be done in a workflow. Again, no error and it behaves very nicely by adding or removing the description based on if there is a Campaign on the opp or not.
So, Flow works, Workflow works, but for the simplest of simplest updates, Process Builder shows such an ugly error that it makes you never ever want to use Process Builder again. Your users do not deserve this crappy experience using Salesforce.
Researching this Error
So of course, the first thing you do is copy and paste the error message into Google hoping to quickly find the solution.
The first post you come across is a Salesforce KB article.
https://help.salesforce.com/apex/HTViewSolution?id=000212174&language=en_US
It says "use criteria to check if the foreign key (aka relationship) field is null before making cross-object references based on that field". Let's try that.
I changed the critera to this - Ooh it works - Wow! Who knew. (Note: In all the times previously I have tried to do anything like this it has never ever worked). I tried it with another criteria (CampignID is changed = true) and tried it with the is null criteria second - no errors. Weird. I have always had errors in the past.
So I changed it to a formula (NOT(ISBLANK([Opportunity].CampaignID)) and even that worked. Previously, I was told to always use formulas rather than criteria, and even that didn't work - is it just luck that this is working now whilst I am trying to write these notes up?
OK, here we go. I changed the formula to NOT(ISNULL([Opportunity].CampaignID)) and the error appeared. See below re ISBLANK AND ISNULL. Why does this occur? Why? The two formulas SHOULD evaluate exactly the same. Especially on a string ID field.
So I changed the criteria to
Yet another way to do it - and it worked - why, why oh why does this work. Why does this work and ISNULL does not work - they SHOULD BE THE SAME THING!
I changed the criteria to [Opportunity].CampaignID != null and that worked - Why? Why does it work?
I changed the criteria to [Opportunity].CampaignID != "" and even that worked - why, when ISNULL does not work?
So I changed the criteria back to ISNULL and yep, it failed again - I just had to check because EVERYTHING ELSE WORKS!
Other Articles
This article says be careful of the order of your criteria http://salesforce.stackexchange.com/questions/92472/lightning-process-builder-exception and then you get devs who don't understand the difference between Process Builder and Flow (because the error messages are SO helpful (not)) and they answer questions like this http://salesforce.stackexchange.com/questions/93471/process-builder-giving-error-the-flow-failed-to-access-the-value-for-example-b - not helpful.
Here's an article that seems to suggest doing multiple different things, all that either work or don't work in certain circumstances https://success.salesforce.com/answers?id=9063000000046YoAAI How confusing!
Fixing this Error
Thanks to the lovely Beth (@bethbrains), she gave me what seems to be the definitive answer on how to fix this.
IF(ISBLANK(lookup__c),null,lookup__r.field__c)
No criteria stuffing around needed, just use that syntax and everything works. No! I don't belive it! And again with the Nulls!
I had tried many other variations on that exact formula, again thinking (no, believing) that null is not in use anymore there is no way I would put null in a formula and NO WAY IN HELL I would combine ISBLANK with Null. So time to try things out. In all cases the criteria node is [Opportuniy].CampaignID Is Changed True
Works
ISBLANK and null
Works
ISBLANK and ""
Just for thoroughness I changed the criteria to No Criteria - Just Execute the Actions and it still worked, which is good to know.
Does Not Work
ISNULL and ""
Does Not Work
ISNULL and null
So at least that is consistent that ISNULLs don't work here and don't work in the Criteria.
Does Not Work
BLANKVALUE ""
Well, now that I have done ALL this stuffing around trying to work this out, I could guess this one would not work, but it was the first thing I tried when I first had this error. To me, then it should have worked. Now I know that Process Builder is finicky and ONLY DO IT ONE WAY.
Does Not Work
BLANKVALUE Null
Of course
Does Not Work
Why wouldn't this work? It's just bizarre. Isn't that syntatically exactly the same as the one that works?
Stupid Things
- The messages refer to Flows, but we are building processes - how annoying. Well remember, Process Builder Behind the Scenes - that a Process is actually a Flow. So that's why the error messages relate to a flow misbehaving. No, knowing that doesn't actually help with any of the annoyances.
- The error message email goes to the user that last activated the process - how stupid!
Weird Things
ISNULL vs ISBLANK
Why oh why does ISNULL even exist in PB? Why does the criteria list say Is Null rather than Is Blank? I have been doing Salesforce since 2011 and in my Admin 201 course we were told to never use ISNULL in formulas, it is deprecated and replaced with ISBLANK (well all salesforce data is stored in the database in strings anyway, so it makes sense to use ISBLANK rather than ISNULL from a pure DB perspective). Here's the help docs that say to not use ISNULL https://help.salesforce.com/apex/HTViewHelpDoc?id=customize_functions.htm&language=en#informational_functions
Process Builder was released some time in 2014?? So why is ISNULL allowed in Process Builder? WHY???
Why does Is Null exist in Criteria? WHY?
Why does using Is null in criteria work but using the ISNULL function cause an error? And why then does ISBLANK not cause an error? WHYYYYYY?
This is a great article on ISNULL vs ISBLANK for formulas http://forcewizard.com/blog/isblank-vs-isnull
Lookup Box
Why oh why is this a thing?
Why are all the fields showing as labels, but the custom Lookup Field displays as the API Name? WHY?
But then in the drop down list it displays as the label again. WHY?
Change API Names
Process Builder will not change the field names if you change them. It doesn't stop you from changing the API Name of the field, like it does in other cases. It will then make the PB fail and you will NOT be able to clone the Process to fix it - you will have to change the API names back to what they were - you did remember didn't you? Then deactivate the Processes, then change the API names, then change them in the Process, the activate and test the process. Oh this is a fabulously detailed post from Johan (@simplysfdc) on this topic http://www.simplysfdc.com/2016/09/salesforce-rename-field-name_4.html
Using __c instead of __r
Why oh why oh why does the field picker enter the relationships with a __c rather than a __r. Since day dot we are told that ALL relationships notation is replace the __c with a __r. Why isn't it the same here? It is just bizarre.
Why aren't scheduled actions visible?
This one is pretty straightforward http://salesforce.stackexchange.com/questions/65734/how-to-add-time-dependent-actions-in-lightning-process-builder