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 Quote variable.

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:

enter image description here

Does anyone know how I might solve this problem?

  • 2
    I'd suggest reducing the scope of your flow to just the bits where you are having an issue (that is, simplify the problem away from gnarliness) and, if still having issues, post the flow using the edit link – cropredy Jan 29 '17 at 0:53
  • What exactly are you doing in the loop? You typically need at least an assignment element in the loop to do anything w the loop variable. – gorav Jan 29 '17 at 20:44
  • The loop does assignments and a few other things. It's just not pictured. – Swisher Sweet Jan 30 '17 at 14:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.