Here's the basic setup. I'm looping a list of
Quotes. For each quote I am looping over
Quote Items. However, when I to update the sObject variable that represents the
Quote I'm currently working with, the object is null (or at least the fields are that I had previously set).
I quadruple checked that I'm not overwriting the object fields down the code path. For some reason, it is empty when try to access it later to perform an update. I get the following error message:
Error Occurred: You can't update or delete an sObject unless it has an ID.
Interestingly, I created a copy of the sObject variable and it maintains its value for a while but it too is later nulled out.
I suspect it has something to do with the nested loops. Perhaps once you're in one the scope is reset somehow.
At this point the flow is getting so gnarley that it almost makes sense to do this in Apex, but this is not what the client wants.
Since posting this, I have narrowed it down to one element that appears to remove some variables out of scope. I created another flow that accepts a text collection and returns a comma-delimited list of strings. If I use this in my loop, the I am unable to access variables that were before this element. It's as if I've lost my execution context once the element returns from the other flow.
The image below explains it more clearly I hope. After the
Quote Items loop has completed, I can access the parent
Quote variable just fine and assign values and update it down the line (see left green path). If I call my flow that creates the comma-delimited string (right path) once it returns, I am no longer able to access my
On the green paths, I can access the variable. This includes the path leading up to the call of the other flow. I tested this by sending an email on each path at those junctions. Only after the call to the other flow does the variable loose value:
Does anyone know how I might solve this problem?