function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
csfdccsfdc 

HELP! Flow, loop, decision, create or update - Who can solve this puzzle?

I'm using a PB Flow and a Visual Flow to achieve the following. When a new Shipment (custom object) record is created, it contains Shipping Address details. If the address is X, and a Building Record (custom object) already exists also with a value X, then use the Visual Flow to relate those records. However, if X does not exist as a Building record, then create a new Building record, mapping over details from the Shipment, and then update the Shipment record to establish a relationship. 

The flow below is not recognizing Buildings in the database and is instead creating new Buildings each time it runs. Can someone please advise on how to solve this puzzle?

User-added image

These are my loop variables:

User-added image

And these are the Decision Conditions I'm using to determine if there is a match between a Building in the Collection and the Variables passed through from the Shipment record (of couse this is not working). 
User-added image
 
Best Answer chosen by csfdc
Piyush Gautam 6Piyush Gautam 6
Hi Cesar,

The problem here is that no matter whether there is a record with an identical address or not, but at the end of the loop, a new record will always be created.
A better approach will be to save the Id of record if found any identical record during looping, into a new variable. At the end of the loop, use a decision component for creating or relating a record. Like if there is any Id in the variable then relate that record and if the variable is NULL then create a new record.

All Answers

Piyush Gautam 6Piyush Gautam 6
Hi Cesar,

The problem here is that no matter whether there is a record with an identical address or not, but at the end of the loop, a new record will always be created.
A better approach will be to save the Id of record if found any identical record during looping, into a new variable. At the end of the loop, use a decision component for creating or relating a record. Like if there is any Id in the variable then relate that record and if the variable is NULL then create a new record.
This was selected as the best answer
csfdccsfdc
Hi Piyush,

Are you suggesting that I keep the Decision criteria as is, but change the Yes Outcome routing from an Update Records element to an Assignment element? In other words, if the Shipment record's shipping address matches that of a Building record, then assign the Building record's ID to a variable, and then after completing the loop go to a new Decision element - like this?

User-added image
Piyush Gautam 6Piyush Gautam 6
Hi Cesar,

Yes, this is the same way as I was telling. Is this working?

Thanks
csfdccsfdc
I am setting the variables now and will then run tests. I will let you know shortly.
csfdccsfdc
Piyush, I am still running into the issue of creating duplicate Building records. [image: Screenshot (155).png] I am simplified the logic on the Match Found Decision element: [image: Screenshot (156).png] I then assigned the Building ID to a variable in the Yes outcome: [image: Screenshot (157).png] And then this is the Decision element criteria for after the loop completes: [image: Screenshot (158).png]
Piyush Gautam 6Piyush Gautam 6
Hi Cesar,

Not able to see the screenshot. There might be a problem with the variable being populated with the Building Id. Please check the variable while debugging the loop.
csfdccsfdc
Hi Piyush. Your advice was critical to helping me solve this problem. I did make changes, so I want to document what I did in case some else runs into this problem. 

First, in the Decision Element I kept the criteria you had suggested, namely to determine whether or not var_Building_Id == NULL. However, as you can see I removed the loop altogether from this flow and instead used a Get Records element. This element is looking at the Building object and uses filter conditions that match shipping details against variables that were captured in the Shipment record that started this flow. 

User-added image
Here are the filter conditions I mentioned:
User-added image
And here the Building variables, which I then use in the Decision element:
User-added image