I've created a flow in my sandbox environment and I'm trying to deploy it to the production environment via a change set, but I'm getting the following error:
Required field is missing: assignNextValueToReference
I understand from this community topic that this is down to a change in newer Salesforce flows from using a separate loop variable into using an automatic variable:
assignNextValueToReference
seems to refer to the old loop variable option, suggesting that the production environment still expects a loop variable, whereas sandbox doesn't even have an option for one anymore
Given that it isn't possible to create an old style loop in the sandbox flow designer, how do I get this deployed to production? The community topic talked about manually editing an XML file, but I don't know how to get to this, and this seems like an error-prone option.
My production environment instance is AP19, which states it is "Spring '20 Patch 23.7", whereas my sandbox environment instance is CS74, which states it is "Summer '20 Patch 7.2". If there isn't a way to deploy this change, how can I fix my environments to be the same?
Best Answer
With a tiny bit of help from Salesforce explaining the procedure, I finally have a resolution. I'll document my procedure here.
I've created this sample flow which simply increments the start date for all contracts in the system by one day:
And we have our loop:
Procedure
Within the .flow definition file (XML), which we'll extract later, we need to create a variable. The easiest way is to actually create the variable within the flow before we start working on the XML. This will save us doing it in XML and prevent us from making mistakes:
Once you've created your loop variable(s), save the flow and activate it.
Next create a file on your computer called
package.xml
and fill it with the following data:Note: Replace AAADummyFlow with the API name of your flow.
Now head on over to https://workbench.developerforce.com/ and login. This isn't an official Salesforce product, but it seems to be the de facto standard for accessign the Metadata API within the community.
Once you're logged in, navigate to over to Migration > Retrieve. Select your
package.xml
as the "unpackaged manifest" and then check the "Single package" box:Click "Next" and then on the next page select "Retrieve". After a while, you'll have the option to "Download ZIP File". Select this.
Download the zip file and extract it somewhere. Your directory should now look like this:
Navigate into the "flows" folder and open your .flow file in your favourite XML-capable editor. Now we want to search for
<loops>
. There will be aloops
entry for each of your loop blocks.So I'll find the one with
<name>Loop_contracts</name>
to match the loop block I created. Just under<locationY>....</locationY>
we want to reference the loop variable we created, so we'll add this line:Replace
ContractLoopItem
with whatever you named your loop variable in the previous step. You should now have something a little bit like this:We're not quite done yet. We now need to find references to
Loop_contracts
and replace them withContractLoopItem
. Note that we should only do this for references. We should not update any<connector>
references because these are links to the loop block, as opposed to the loop items. So in mine, I have anassignToReference
that needs updatingm, and aninputReference
that needs updating. We'll replace theLoop_contracts
value within these withContractLoopItem
:Now that we've found and replaced all the instances of the loop items, save the file and zip it all back up:
Now head back to Workbench and go to Migration > Deploy. Select the file you just edited, and then check "Rollback on Error" and "Single Package". I recommend deploying this back to your sandbox org first. If you're deploying direct to production, be sure to set test level to something other than "NoTestRun":
Click "Next" and then click "Deploy". If all has gone well you should see Status: Succeded.
Now go back to Flows on Salesforce and you can see we have a third version of our flow now:
We can also wee that the loop now references our variable:
Notes
I highly recommend checking every block that uses the loop item to ensure that everything has been assigned properly. Be sure you test your updated flow before you deploy it to production.
I read somewhere that Mac adds extra things to zip files, which could lead to a message stating that package.xml can't be found. I also found that not selecting "Single Package" led to this.
I hope this helps!